Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Results different when using Step Into vs. Run of VBA code

Status
Not open for further replies.

techuser123

Technical User
Sep 2, 2008
3
US
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
 
What about this ?
Code:
If fs.DriveExists(sDrive) Then nw.RemoveNetworkDrive sDrive, True
[!]DoEvents[/!]
nw.MapNetworkDrive sDrive, sUNC

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top