Article ID: 138905
Article Last Modified on 1/19/2007
Option Explicit
Declare Function WNetAddConnection Lib "mpr.dll" Alias _
"WNetAddConnectionA" (ByVal lpszNetPath As String, _
ByVal lpszPassword As String, ByVal lpszLocalName As String) _
As Long
Declare Function WNetCancelConnection Lib "mpr.dll" Alias _
"WNetCancelConnectionA" (ByVal lpszName As String, _
ByVal bForce As Long) As Long
Const WN_SUCCESS = 0 ' The function was successful.
Const WN_NET_ERROR = 2 ' An error occurred on the network.
Const WN_BAD_PASSWORD = 6 ' The password was invalid.
Function AddConnection(MyShareName$, MyPWD$, UseLetter$) As Integer
On Local Error GoTo AddConnection_Err
AddConnection = WNetAddConnection(MyShareName$, MyPWD$, _
UseLetter$)
AddConnection_End:
Exit Function
AddConnection_Err:
AddConnection = Err
MsgBox Error$
Resume AddConnection_End
End Function
NOTE: Some of the possible return values for the AddConnection()
function include WN_SUCCESS, WN_NET_ERROR, and WN_BAD_PASSWORD. Other
run-time errors could be returned from the function; therefore, error
trapping should be implemented to handle any problems.
Function CancelConnection(UseLetter$, Force%) As Integer
On Local Error GoTo CancelConnection_Err
CancelConnection = WNetCancelConnection(UseLetter$, Force%)
CancelConnection_End:
Exit Function
CancelConnection_Err:
CancelConnection = Err
MsgBox Error$
Resume CancelConnection_End
End Function
NOTE: Two of the most common return values for CancelConnection() are
WN_SUCCESS and WN_NET_ERROR.
?AddConnection(<"\\servername\sharename">, <"MyPwd">, <"y:">)
?CancelConnection(<"y:">, 0)
138904 Connecting to the First Available Network Drive (95/97)
Keywords: kbinfo kbprogramming KB138905