Hier ist eine Lösung. Es erstellt ein lokales zugeordnetes Netzlaufwerk des Netzwerkspeicherorts, als es Daten importiert, als würde es aus einer CSV-Datei in einem lokalen Laufwerk importieren; Wenn es fertig ist, entfernt es das zugeordnete Laufwerk.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNet = CreateObject("WScript.Network")
strUsername = Domain\username
strPassword = Password
strDestination = GetNextLetter("F", wshNet)
wshNet.MapNetworkDrive strDestination, "\\ServerAddress\Folder", , strUsername, strPassword
DoCmd.TransferText acImportDelim, , "Daily_data", strDestination & "\RestOfThePathIncludingFileName", True
wshNet.RemoveNetworkDrive strDestination, True
Set objFSO = Nothing
Set wshNetwork = Nothing
Diese Lösung wurde von https://www.experts-exchange.com/questions/21108808/using-vba-to-copy-file-to-a-network-share-with-username-and-password.html
Function GetNextLetter(DriveLetter, wshNet)
'Start x at the ascii value of the drive letter to start the search
'unless something is passed in. This sample uses capital letters and
'starts at F.
If IsEmpty(DriveLetter) Then
x = 70
Else
x = Asc(DriveLetter)
End If
Set oDrives = wshNet.EnumNetworkDrives
'Step by two since the first item in the collection is the drive letter
'and the second item is the network mapping
For i = 0 To oDrives.Count - 1 Step 2
If Chr(x) & ":" = oDrives.Item(i) Then
x = x + 1
End If
Next
GetNextLetter = Chr(x) & ":"
End Function
folgende getan