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)
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
ErrorString
Returns a String value that represents the ODBC error string.
Dim strErrorString As String
strErrorString = Application.ODBCErrors(1).ErrorString
SqlState
Returns the SQL state error.
For an explanation of the specific error, see your SQL documentation.
With Worksheets(1).QueryTables(1)
.Refresh
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
Next
Else
MsgBox "Query complete: all records returned."
End If
End With