Access/VBA Library


Maps a share to a drive and returns a Boolean indicating if the mapping was succesfull.


MapShare( drive, share [, persistent] [, closeApplicationOnFail] [, userId] [, password] )
Name Type Description
drive String Required. Drive to be used for mapping.
share String Required. Full path of the share to be mapped.
persistent Boolean Optional. Indicating if the mapping should be permanent or not.
Default: False
closeApplicationOnFail Boolean Optional. Indicating if the application should be close when the mapping fails.
Default: True
userId String Optional. UserId when the share is a protected.
Default: ""
password String Optional. Password of the UserId when the share is protected.
Default: ""
Return value

Boolean : True when the mapping was succesfull, otherwise False when closeApplicationOnFail is set to False.

Public Function MapShare(drive As String, _
                         share As String, _
                         Optional ByVal persistent As Boolean = False, _
                         Optional ByVal closeApplicationOnFail As Boolean = True, _
                         Optional ByVal userId As String = "", _
                         Optional ByVal password As String = "") As Boolean

On Error GoTo MapShare_Error
    Dim objNetWork
    drive = GetDriveLetter(drive) & ":"
    MapShare = False
    Set objNetWork = CreateObject("WScript.Network")
    If userId = "" Then
        Call objNetWork.MapNetworkDrive(drive, share, persistent)
        Call objNetWork.MapNetworkDrive(drive, share, persistent, userId, password)
    End If
    MapShare = True

    On Error Resume Next
    Set objNetWork = Nothing
    Exit Function
    Call Application.Quit(acQuitSaveAll)
    Call ShowError(functionName:=MapShare)
    If closeApplicationOnFail Then
        Resume MapShare_Close_Application
        Resume MapShare_Exit
    End If
End Function

See also

  • GetDriveLetter
  • ShowError