By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,107 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,107 IT Pros & Developers. It's quick & easy.

Problem Mapping a NetworkDrive

P: n/a
Hi all!
I have a procedure to Map a Network Drive on Shared Folder from a server
in my intranet (this heppens after the user has put Username and
Password in a form used for Domain Authentication)

The code is already functioning in VB6 but i would like to apply it also
in a Acc97 application. Unfortunately the Api call doesn't work.

Here's the code

------------------------------------

-------------
DECLARATIONS
-------------

Private Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type

Private Declare Function WNetAddConnection2 Lib "mpr" _
Alias "WNetAddConnection2A" _
(lpNetResource As NETRESOURCE, _
ByVal lpPassword As String, _
ByVal lpUserName As String, _
ByVal dwFlags As Long) As Long
Private Const ERROR_SUCCESS = 0
Private Const CONNECT_UPDATE_PROFILE = &H1
Private Const RESOURCETYPE_DISK = &H1
Private Const RESOURCETYPE_PRINT = &H2
Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCE_GLOBALNET = &H2
Private Const RESOURCEDISPLAYTYPE_SHARE = &H3
Private Const RESOURCEUSAGE_CONNECTABLE = &H1

Dim NETR As NETRESOURCE

Dim errInfo As Long
Dim result As Boolean

Dim strRemoteDrv as string
Dim strNetDrive

---------
PROCEDURE
---------

....
......
strNetDrive = "q:"
strRemoteDrv = "\\svnt01\orehr"

With NETR
.dwScope = RESOURCE_GLOBALNET
.dwType = RESOURCETYPE_DISK
.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE
.dwUsage = RESOURCEUSAGE_CONNECTABLE
.lpRemoteName = strRemoteDrv
.lpLocalName = strNetDrive
End With

errInfo = WNetAddConnection2(NETR, LCase(Me.txtPassword),
LCase(Me.txtUserName), CONNECT_UPDATE_PROFILE)

result = errInfo = ERROR_SUCCESS

If Not result Then
MsgBox "Impossibile mappare l'unità di rete del BackEnd. Impossibile
continuare.", vbCritical + vbOKOnly, "LeOreHR"
DoCmd.Quit
End If
-------------------------------------

Me.txtUserName e Me.txtPassword are supplied in a form and are the same
used for the domain's login.
The procedure is executed only if the Q: drive in not mapped (if its
mapped to a different share the app stops and close automatically).

I can't understand where the problem is and why the same code is ok for
VB6 and not for VBA.

Thanks to anyone who'll give me some help
bye
Mirx

PS: sorry for my bad english
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Nov 12 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.