Class OLEDBError (Excel VBA)
The class OLEDBError represents an OLE DB error returned by the most recent OLE DB query.
Set
To use a OLEDBError class variable it first needs to be instantiated, for example
Dim lngIndex As Long: lngIndex =
Dim oleerOLEDBError As OLEDBError
oleerOLEDBError = Application.OLEDBErrors(Index:=lngIndex)
The following procedures can be used to set variables of type OLEDBError: OLEDBErrors.Item and Application.OLEDBErrors
For Each
Here is an example of processing the OLEDBError items in a collection.
Dim oleerOLEDBError As OLEDBError
For Each oleerOLEDBError In Application.OLEDBErrors
Next oleerOLEDBError
ErrorString
Returns a String value that represents the ODBC error string.
Native
Returns a provider-specific numeric value that specifies an error. The error number corresponds to an error condition that resulted after the most recent OLE DB query.
Set objEr = Application.OLEDBErrors(1)
MsgBox "The following error occurred:" & _
objEr.Number & ", " & objEr.Native & ", " & _
objEr.ErrorString & " : " & objEr.SqlState
Number
Returns a numeric value that specifies an error. The error number corresponds to a unique trap number corresponding to an error condition that resulted after the most recent OLE DB query.
Set objEr = Application.OLEDBErrors(1)
MsgBox "The following error occurred:" & _
objEr.Number & ", " & objEr.Native & ", " & _
objEr.ErrorString & " : " & objEr.SqlState
Parent
Returns the parent object for the specified object. Read-only.
SqlState
Returns the SQL state error.
For an explanation of the specific error, see your SQL documentation.
Stage
Returns a numeric value specifying the stage of an error that resulted after the most recent OLE DB query.
Set objEr = Application.OLEDBErrors(1)
MsgBox "The following error occurred:" & _
objEr.Number & ", " & objEr.Native & ", " & _
objEr.Stage & ", " & _
objEr.ErrorString & " : " & objEr.SqlState
OLEDBErrors.Count
Returns a Long value that represents the number of objects in the collection.
OLEDBErrors.Item
Returns a single object from a collection.
Syntax : expression.Item (Index)
Index: The index number for the object.
Set objEr = Application.OLEDBErrors.Item(1)
MsgBox "The following error occurred:" & _
objEr.ErrorString & " : " & objEr.SqlState
OLEDBErrors.Parent
Returns the parent object for the specified object. Read-only.