SQLError Function
Description
Don't use SQLError and the other ODBC functions in the Xlodbc.xla add-in; use the objects, methods, and properties in the Data Access Objects (DAO) library instead.
SQLError returns detailed error information when it's called after one of the other ODBC functions fails. If SQLError itself fails, it cannot return error information.
Error information is defined and stored in memory whenever an ODBC function fails. To make the error information available, call the SQLError function.
SQLError provides detailed error information only about errors that occur when an ODBC function fails. It doesn't provide information about Microsoft Excel errors.
This function is contained in the Xlodbc.xla add-in (ODBC Add-In on the Macintosh). Before you use the function, you must establish a reference to the add-in by using the References command (Tools menu).
Syntax
SQLError( )
Return Value
If there are errors, SQLError returns detailed error information in a two-dimensional array in which each row describes one error.
Each row has the following three fields for information obtained through the SQLError function call in ODBC:
- A character string that indicates the ODBC error class and subclass
- A numeric value that indicates the data source native error code.
- A text message that describes the error.
If a function call generates multiple errors, SQLError creates a row for each error.
If there are no errors from a previous ODBC function call, this function returns only Error 2042.
See Also
SQLBind function, SQLClose function, SQLExecQuery function, SQLGetSchema function, SQLOpen function, SQLRequest function, SQLRetrieve function, SQLRetrieveToFile function.
Example
This example generates an intentional error by attempting to open a connection to the NWind sample database by using an incorrect connection string (NWind is misspelled). The error information is displayed on Sheet1.
chan = SQLOpen("DSN=NWin")
returnArray = SQLError()
For i = LBound(returnArray, 1) To UBound(returnArray, 1)
Worksheets("Sheet1").Cells(1, i).Formula = returnArray(i)
Next i
SQLClose chan