Using the VBA Err Object and ADO Errors Collection
Sub DBError()
Dim conn As New ADODB.Connection
Dim errADO As ADODB.Error
On Error GoTo CheckErrors
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\my.mdb"
CheckErrors:
Debug.Print "VBA error number: " & Err.Number & vbCrLf & " (" & Err.Description & ")"
Debug.Print "Listed below is information " & "regarding this error " & vbCrLf & "contained in the ADO Errors collection."
For Each errADO In conn.Errors
Debug.Print vbTab & "Error Number: " & errADO.Number
Debug.Print vbTab & "Error Description: " & errADO.Description
Debug.Print vbTab & "Jet Error Number: " & errADO.SQLState
Debug.Print vbTab & "Native Error Number: " & errADO.NativeError
Debug.Print vbTab & "Source: " & errADO.Source
Debug.Print vbTab & "Help Context: " & errADO.HelpContext
Debug.Print vbTab & "Help File: " & errADO.HelpFile
Next
End Sub
Related examples in the same category