P
Pastor Del
I'm using the following code that I found online to connect to a server. It
works well for me, but I do not know how to disconnect from the server with
ConnectServer. Can someone provide me with some code sample(s) to do this?
My application is coded in Access 2000 & will be working in an environment
with Access 2000 2003 & 2007
Private Sub cmdConnect_Click()
Dim ret As Long
ret = ConnectServer("\\MyServerName\f\DBWorkspace\SecureFolder",
"TSI\Database", "database")
If ret <> NO_ERROR Then
'handle your error
MsgBox "Error"
Else
'use the share
MsgBox "No Error"
End If
End Sub
Public Function ConnectServer(sharename As String, username As String,
password As String) As Long
NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = "" ' If undefined, Connect with no device
NetR.lpRemoteName = sharename ' Your valid share
MyUser = username
MyPass = password
' If the UserName and Password arguments are NULL, the user context
' for the process provides the default user name.
ConnectServer = WNetAddConnection2(NetR, MyPass, MyUser, 0)
End Function
works well for me, but I do not know how to disconnect from the server with
ConnectServer. Can someone provide me with some code sample(s) to do this?
My application is coded in Access 2000 & will be working in an environment
with Access 2000 2003 & 2007
Private Sub cmdConnect_Click()
Dim ret As Long
ret = ConnectServer("\\MyServerName\f\DBWorkspace\SecureFolder",
"TSI\Database", "database")
If ret <> NO_ERROR Then
'handle your error
MsgBox "Error"
Else
'use the share
MsgBox "No Error"
End If
End Sub
Public Function ConnectServer(sharename As String, username As String,
password As String) As Long
NetR.dwScope = RESOURCE_GLOBALNET
NetR.dwType = RESOURCETYPE_DISK
NetR.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
NetR.dwUsage = RESOURCEUSAGE_CONNECTABLE
NetR.lpLocalName = "" ' If undefined, Connect with no device
NetR.lpRemoteName = sharename ' Your valid share
MyUser = username
MyPass = password
' If the UserName and Password arguments are NULL, the user context
' for the process provides the default user name.
ConnectServer = WNetAddConnection2(NetR, MyPass, MyUser, 0)
End Function