ここでは、ソリューションです。これは、ローカルドライブ内のcsvファイルからインポートするようにデータをインポートするよりも、ネットワークロケーションのローカルにマップされたネットワークドライブを作成します。終了すると、マップされたドライブが削除されます。
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
このソリューションは、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
から、次の行われていました