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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change curdir to network dir

Status
Not open for further replies.

nkrst1

Programmer
Feb 13, 2001
49
0
0
US
I'm trying to get the CurDir variable to be a directory on the network (which is actually my documents mapped to '\\SERVER\USER_MYDOCUMENTS')... i know i need to change the drive before i can change the path, but chdrive doesn't like anything but a letter:

chdrive "\\SERVER"

will not work if the current drive is local, like 'C' or 'F'. If the CurDir is already '\\SERVER', then I can change within that directory or out of it to a local drive, but I can't go from local drive to a server directory (hope that makes sense). I'd rather not have my users remap a drive for my documents just so they can just this.

Any help is appreciated.

Thanks,

-n-
 
This module returns the UNC address from a drive letter it may be of use or give you some ideas
Option Compare Database
Option Explicit

' These represent the possible returns errors from API.
Public Const ERROR_BAD_DEVICE = 1200&
Public Const ERROR_CONNECTION_UNAVAIL = 1201&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_MORE_DATA = 234
Public Const ERROR_NOT_SUPPORTED = 50&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Public Const ERROR_NO_NETWORK = 1222&
Public Const ERROR_NOT_CONNECTED = 2250&
Public Const NO_ERROR = 0

' This API declaration is used to return the
' UNC path from a drive letter which needs to be in the format e.g. F:
Declare Function WNetGetConnection Lib "mpr.dll" Alias _
"WNetGetConnectionA" _
(ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, _
cbRemoteName As Long) As Long


Function GetUNCPath(strDriveLetter As String) As String
On Local Error GoTo GetUNCPath_Err
Dim Msg As String, lngReturn As Long
Dim lpszLocalName As String
Dim lpszRemoteName As String
Dim cbRemoteName As Long
lpszLocalName = strDriveLetter
lpszRemoteName = String$(255, Chr$(32))
cbRemoteName = Len(lpszRemoteName)
lngReturn = WNetGetConnection(lpszLocalName, _
lpszRemoteName, _
cbRemoteName)
Select Case lngReturn
Case ERROR_BAD_DEVICE
Msg = "Error: Bad Device"
Case ERROR_CONNECTION_UNAVAIL
Msg = "Error: Connection Un-Available"
Case ERROR_EXTENDED_ERROR
Msg = "Error: Extended Error"
Case ERROR_MORE_DATA
Msg = "Error: More Data"
Case ERROR_NOT_SUPPORTED
Msg = "Error: Feature not Supported"
Case ERROR_NO_NET_OR_BAD_PATH
Msg = "Error: No Network Available or Bad Path"
Case ERROR_NO_NETWORK
Msg = "Error: No Network Available"
Case ERROR_NOT_CONNECTED
Msg = "Error: Not Connected"
Case NO_ERROR
' all is successful...
End Select
If Len(Msg) Then
If lngReturn <> ERROR_NOT_CONNECTED Then
MsgBox Msg, vbInformation
Else
' it's probably a local address with no UNC as we've already browsed to it
Exit Function
End If
Else
' return the UNC through the function.
MsgBox Left$(lpszRemoteName, cbRemoteName)
GetUNCPath = Left$(lpszRemoteName, cbRemoteName)
End If
GetUNCPath_End:
Exit Function
GetUNCPath_Err:
MsgBox Err.Description, vbInformation
Resume GetUNCPath_End
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top