Error Object, Errors Collection, and Description, Number, Source, HelpFile, and HelpContext Properties Example

This example forces an error, traps it, and displays the Description, Number, Source, HelpContext, and HelpFile properties of the resulting Error object.

Sub DescriptionX()

    Dim dbsTest As Database

    On Error GoTo ErrorHandler

    ' Intentionally trigger an error.
    Set dbsTest = OpenDatabase("NoDatabase")

    Exit Sub

ErrorHandler:
    Dim strError As String
    Dim errLoop As Error

    ' Enumerate Errors collection and display properties of 
    ' each Error object.
    For Each errLoop In Errors
        With errLoop
            strError = _
                "Error #" & .Number & vbCr
            strError = strError & _
                "  " & .Description & vbCr
            strError = strError & _
                "  (Source: " & .Source & ")" & vbCr
            strError = strError & _
                "Press F1 to see topic " & .HelpContext & vbCr
            strError = strError & _
                "  in the file " & .HelpFile & "."
        End With
        MsgBox strError
    Next

    Resume Next

End Sub