Class ODBCError (Excel VBA)

The class ODBCError represents an ODBC error generated by the most recent ODBC query.


To use a ODBCError class variable it first needs to be instantiated, for example

Dim odber as ODBCError
Set odber = Application.ODBCErrors(Index:=1)

ODBCError class variables can be set using the ODBCErrors.Item procedure.

For Each

Here is an example of processing the ODBCError items in a collection.

Dim odber As ODBCError
For Each odber In Application.ODBCErrors
Next odber


Returns a String value that represents the ODBC error string.

Dim strErrorString As String
strErrorString = Application.ODBCErrors(1).ErrorString


Returns the SQL state error.

For an explanation of the specific error, see your SQL documentation.

With Worksheets(1).QueryTables(1) 
 Set errs = Application.ODBCErrors 
 If errs.Count > 0 Then 
 Set r = .Destination.Cells(1) 
 r.Value = "The following errors occurred:" 
 c = 0 
 For Each er In errs 
 c = c + 1 
 r.offset(c, 0).value = er.ErrorString 
 r.offset(c, 1).value = er.SqlState 
 MsgBox "Query complete: all records returned." 
 End If 
End With


Returns a Long value that represents the number of objects in the collection.

Dim lngCount As Long
lngCount = Application.ODBCErrors.Count


Returns a single object from a collection.

Item (Index)

Index: The index number for the object.