Access/VBA Library

RemoveMapping

Removes an existing drive mapping and returns a Boolean indicating if the removal was succesfull.

Syntax

RemoveMapping( drive [, persistent] )
Parameters
Name Type Description
drive String Required. Drive to be removed.
persistent Boolean Optional. Indicates if the removal should be permanent or not.
Default: False
Return value

Boolean : True on success, False on fail.

Code
Public Function RemoveMapping(ByVal drive As String, _
                              Optional ByVal persistent As Boolean = False) As Boolean
    Dim objNetWork
    
On Error GoTo RemoveMapping_Error
    RemoveMapping = False
    
    drive = GetDriveLetter(drive) & ":"

    Set objNetWork = CreateObject("WScript.Network")
    
    objNetWork.RemoveNetworkDrive drive, True, persistent

    RemoveMapping = True
RemoveMapping_Exit:
    On Error Resume Next
    Set objNetWork = Nothing
    Exit Function

RemoveMapping_Error:
    Call ShowError(functionName:="RemoveMapping")
    Resume RemoveMapping_Exit

End Function
Filesystemtag:FilesystemNetworktag:Network

See also

  • GetDriveLetter