Export (0) Print
Expand All

SQLError Function

Office 2007

It is recommended that you use the objects, methods, and properties in the Microsoft ActiveX Data Objects (ADO) library instead of SQLError and the other ODBC functions in the Xlodbc.xla add-in.

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 does not 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 (on the Tools menu) in the Visual Basic Editor.


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.

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


Community Additions

ADD
Show:
© 2015 Microsoft