2016-04-13 15 views
0

Bir ağ paylaşımından csv'yi erişim veritabanımdaki yeni bir tabloya almak için basit bir vba betiğim var. Ağ paylaşımına erişimim var ve makinemden iyi çalışıyor. Komut dosyasını da çalıştırabilmek için ağ paylaşımına erişimi olmayan diğer kişileri de istiyorum. Gerekli izinlere sahip genel bir ağ hesabım var ve bunu komut dosyasına yerleştirebileceğimi umuyor muyum?DoCmd.TransferText ağ izinlerini kullanarak csv dosyasını MS Access'e alma

Bu ve diğer forumlara ve MSDN'ye bir göz attım ve bunu nasıl yapamayacağımı, çoğu zaman veritabanı ve veritabanı bağlantı izinleriyle ilgileniyor gibi görünmüyorum. İşte Teşekkür

cevap

0

bir çözümdür. Yerel bir sürücüde csv dosyasından içe aktardığı verileri içe aktardığından, ağ konumunun yerel bir eşlenmiş ağ sürücüsü oluşturur; bittiğinde, eşlenen sürücüyü kaldırır.

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 

Bu çözelti 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 
aşağıdaki yapıldı
İlgili konular