Access/VBA Library


Wrapper around the MsgBox function to show an error.


ShowError( [ErrorMessage] [, functionName] )
Name Type Description
ErrorMessage String Optional. The errormessage to be shown. If omitted the description property of the Err object is shown.
Default: ""
functionName String Optional. Name of the function which raised the error. If specified the functionname will be part of the errormessage.
Default: ""
Public Sub ShowError(Optional ByVal ErrorMessage As String = "", _
                     Optional ByVal functionName As String = "")

    ' If no message specified then take message from Err object
    If ErrorMessage = "" Then
        ErrorMessage = Err.Description
    End If

    ' Add FunctionName to locate the source of the error
    If functionName <> "" Then
        ErrorMessage = ErrorMessage & vbCrLf & vbCrLf & "Occured in function: " & functionName
    End If
    ' Show the error
    MsgBox ErrorMessage, vbOKOnly Or vbExclamation, GetApplicationTitle()
End Sub


See also

  • GetApplicationTitle