AW: Auf Datei als anderer Benutzer zugreifen
23.02.2026 18:18:31
Marc
warum ist die Datenbank nicht auf einem Ort wo alle zugreifen können.
Sobald die mehrere Dateien, hast, wirst du unterschiedliche Datenstände haben..
allerdings gibt es die Möglichkeit mit VBA eine temporäre Netzwerkadresse zu öffnen und zu benutzen...
ähnlich dem..
#If VBA7 Then
Private Declare PtrSafe Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" ( _
ByRef lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUsername As String, _
ByVal dwFlags As Long) As Long
Private Declare PtrSafe Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" ( _
ByVal lpName As String, _
ByVal dwFlags As Long, _
ByVal fForce As Boolean) As Long
#Else
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" ( _
ByRef lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUsername As String, _
ByVal dwFlags As Long) As Long
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" ( _
ByVal lpName As String, _
ByVal dwFlags As Long, _
ByVal fForce As Boolean) As Long
#End If
Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type
Private Const RESOURCETYPE_DISK As Long = &H1
'Verbindung
Function ConnectNetworkShare( _
ByVal remotePath As String, _
ByVal user As String, _
ByVal password As String) As Boolean
Dim nr As NETRESOURCE
Dim result As Long
nr.dwType = RESOURCETYPE_DISK
nr.lpRemoteName = remotePath
nr.lpLocalName = vbNullString ' Kein Laufwerksbuchstabe
result = WNetAddConnection2(nr, password, user, 0)
ConnectNetworkShare = (result = 0)
End Function
'Verbindung Trennen
Sub DisconnectNetworkShare(ByVal remotePath As String)
WNetCancelConnection2 remotePath, 0, True
End Sub
Sub Beispiel()
Dim sharePath As String
sharePath = "\\Server01\Daten"
If ConnectNetworkShare(sharePath, "DOMAIN\UserX", "Passwort123") Then
' Beispielzugriff
MsgBox Dir(sharePath & "\test.xlsx")
DisconnectNetworkShare sharePath
Else
MsgBox "Verbindung fehlgeschlagen!"
End If
End Sub