Access/VBA Library

ShowError

Wrapper around the MsgBox function to show an error.

Syntax

ShowError( [ErrorMessage] [, functionName] )
Parameters
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: ""
Code
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

Interactiontag:Interaction

See also

  • GetApplicationTitle