Doug Steele
dbdoug at gmail.com
Mon Oct 22 13:04:38 CDT 2012
This may be totally irrelevant, but I had an Access db that was having
problems when some users were using drive letters and others were using
UNC. So I found the following function which converts a drive letter to a
unc path:
Doug
' This API declaration is used to return the
' UNC path from a drive letter.
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 lngReturn <> 0 Then
GetUNCPath = ""
Else
GetUNCPath = Left$(lpszRemoteName, cbRemoteName)
GetUNCPath = Left(GetUNCPath, InStr(GetUNCPath, Chr(0)) - 1)
End If
'End If
GetUNCPath_End:
Exit Function
GetUNCPath_Err:
MsgBox Err.Description, vbInformation
Resume GetUNCPath_End
End Function