SQLError Function

     

Don’t use SQLError and the other ODBC functions in the Xlodbc.xla add-in; use the objects, methods, and properties in the Microsoft ActiveX Data Objects (ADO) 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. Before you use the function, you must establish a reference to the add-in by using the References command (Tools menu).

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:

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.

Example

This example generates an intentional error by attempting to open a connection to the Northwind database by using an incorrect connection string (Northwind is misspelled). The error information is displayed on Sheet1.

chan = SQLOpen("DSN=Nortwind")
returnArray = SQLError()
For i = LBound(returnArray, 1) To UBound(returnArray, 1)
    Worksheets("Sheet1").Cells(1, i).Formula = returnArray(i)
Next i
SQLClose chan