Access/VBA Library

GetShare

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

Syntax

GetShare( drive )
Parameters
Name Type Description
drive String Required. Drive to get the mapped shared from.
Return value

String : Full path of the network share the drive is mapped to. When the drive does not exist an empty string is returned.

Code
Function GetShare(ByVal drive As String) As String
    Dim i As Integer
    
    drive = GetDriveLetter(drive)
    
    With CreateObject("WScript.Network").EnumNetworkDrives
        For i = 0 To .Count - 1 Step 2
            If GetDriveLetter(.Item(i)) = drive Then
                GetShare = .Item(i + 1)
                Exit Function
            End If
        Next i
    End With
    ' When arrived here, drive is not found
    GetShare = ""
End Function
Filesystemtag:FilesystemNetworktag:Network

See also

  • GetDriveLetter