2016-04-13 17 views
0

シンプルなvbaスクリプトを使用して、ネットワーク共有からcsvを自分のアクセスデータベースの新しいテーブルにインポートします。ネットワーク共有にアクセスでき、マシンから正常に実行されます。スクリプトを実行するためにネットワーク共有にアクセスできない人もいます。私は必要な権限を持つ一般的なネットワークアカウントを持っており、これをスクリプトに埋め込むことができると考えていますか?DoCmd.TransferTextネットワーク権限を使用してmsアクセスにcsvファイルをインポートする

このフォーラムや他のフォーラムやMSDNで一見したことがありますが、これを行う方法がわかりません。ほとんどの場合、データベースとデータベースの接続許可が必要です。

ありがとう

答えて

0

ここでは、ソリューションです。これは、ローカルドライブ内の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 
から、次の行われていました
関連する問題