Access/VBA Library

GetDrive

Returns a String containing the drive the share is mapped to.

Syntax

GetDrive( share )
Parameters
Name Type Description
share String Required. Full path of the network share.
Return value

String : The drive the share is mapped to (like "P:"). If no mapping is found, and empty string is returned.

Code
Public Function GetDrive(share As String) As String
    Dim i As Integer
    ' Try to find an existing mapping to the share
    With CreateObject("WScript.Network").EnumNetworkDrives
        For i = 0 To .Count - 1 Step 2
            If .Item(i + 1) = share Then
                GetDrive = .Item(i)
                Exit Function
            End If
        Next i
    End With
    
    GetDrive = ""
End Function
Filesystemtag:FilesystemNetworktag:Network