techuser123
Technical User
I am trying to use VBA code on an Access form to map (or remap) a network drive. When the drive is remapped, the UNC name remains unchanged in Windows Explorer even though the remapping was successful. If I step through the same code in the debugger, the UNC name gets updated appropriately.
Why is Access acting differently between Run and Step Into? How can I get the code to update the UNC without having to step through it? I have even tried inserting a pause between the RemoveNetworkDrive and MapNetworkDrive commands, but that does not have any effect.
Here is a sample of the code I am using. I simply change the parameter being passed to the Map_Drive routine to switch between servers 1 and 2.
Thank you in advance for any insight you can provide.
Private Sub Test_It()
Call Map_Drive(1)
End Sub
Private Sub Map_Drive(iLeg As Integer)
Dim nw As Object, fs As Object
Dim sUNC As String
Const sDrive As String = "Y:"
sUNC = Choose(iLeg, "\\Server1\Test1", "\\Server2\Test2")
Set nw = CreateObject("WScript.Network")
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.DriveExists(sDrive) Then nw.RemoveNetworkDrive sDrive, True
nw.MapNetworkDrive sDrive, sUNC
Set nw = Nothing
Set fs = Nothing
End Sub
Why is Access acting differently between Run and Step Into? How can I get the code to update the UNC without having to step through it? I have even tried inserting a pause between the RemoveNetworkDrive and MapNetworkDrive commands, but that does not have any effect.
Here is a sample of the code I am using. I simply change the parameter being passed to the Map_Drive routine to switch between servers 1 and 2.
Thank you in advance for any insight you can provide.
Private Sub Test_It()
Call Map_Drive(1)
End Sub
Private Sub Map_Drive(iLeg As Integer)
Dim nw As Object, fs As Object
Dim sUNC As String
Const sDrive As String = "Y:"
sUNC = Choose(iLeg, "\\Server1\Test1", "\\Server2\Test2")
Set nw = CreateObject("WScript.Network")
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.DriveExists(sDrive) Then nw.RemoveNetworkDrive sDrive, True
nw.MapNetworkDrive sDrive, sUNC
Set nw = Nothing
Set fs = Nothing
End Sub