ACC: Using the Windows 3.1 API to Connect to Network ResourcesID: Q90862
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
You can use the Microsoft Windows version 3.1 application programming
interface (API) to connect to and disconnect from network drives and
printers in an Access Basic module.
To use the API functions, follow these steps. You will probably want to
use variables for the parameters.
NOTE: In the following sample code, an underscore (_) is used as a line-
continuation character. Remove the underscore from the end of the line
when re-creating this code in Access Basic.
'------------------------------------------------------------------
Option Explicit
Declare Function WNetAddConnection% Lib "User" (ByVal lpszNetPath$,_
ByVal lpszPassword$,_
ByVal lpszLocalName$)
Declare Function WNetCancelConnection% Lib "User" (ByVal lpszName$,_
ByVal fForce%)
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.
Dim Results%, Force%
'------------------------------------------------------------------
Function AddConnection ()
' lpszLocalName$ can be in the form D: or E: and LPT1 or LPT2.
Results% = WNetAddConnection("\\server\share", "password", "y:")
End Function
Function CancelConnection ()
Force%=1
' NOTE: If Force%=0 and files were open,
' the connection will not be 'canceled.
Results% = WNetCancelConnection("y:", 1)
End Function
For more information about Win32 APIs, please see the following article
in the Microsoft Knowledge Base:
Q138905 ACC95: Using the Win32 API to Connect to Network Resources
7.0
Keywords : kbprg
Version : 1.0 1.10 2.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: March 10, 1999