Description, HelpContext, HelpFile, NativeError, Number, Source, SQLState Properties Example
This example triggers an error, traps, it, and displays the Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState properties of the resulting Error object.
Public Sub DescriptionX() Dim cnn1 As ADODB.Connection Dim errLoop As ADODB.Error Dim strError As String On Error GoTo ErrorHandler ' Intentionally trigger an error. Set cnn1 = New ADODB.Connection cnn1.Open "nothing" Exit Sub ErrorHandler: ' Enumerate Errors collection and display properties of ' each Error object. For Each errLoop In cnn1.Errors With errLoop strError = "Error #" & .Number & vbCr & _ " " & .Description & vbCr & _ " (Source: " & .Source & ")" & vbCr & _ " (SQL State: " & .SQLState & ")" & vbCr & _ " (NativeError: " & .NativeError & ")" & vbCr If .HelpFile = "" Then strError = strError & _ " No Help file available" & _ vbCr & vbCr Else strError = strError & _ " (HelpFile: " & .HelpFile & ")" & vbCr & _ " (HelpContext: " & .HelpContext & ")" & _ vbCr & vbCr End If End With Debug.Print strError Next Resume Next End Sub
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.