This documentation is archived and is not being maintained.

SQLClose Function

Office 2007

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

SQLClose closes a connection to an external data source.

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.


SQLClose(ConnectionNum)

Return Value

If the connection is successfully closed, this function returns 0 (zero) and the connection ID is no longer valid.

If ConnectionNum is not valid, this function returns Error 2015.

If SQLClose is unable to disconnect from the data source, it returns Error 2042.

Example

This example runs a query on the Northwind database. The result of the query, displayed on Sheet1, is a list of all products that are currently on order.

databaseName = "Northwind"
queryString = _
    "SELECT * FROM product.dbf WHERE (product.ON_ORDER<>0)"
chan = SQLOpen("DSN=" & databaseName)
SQLExecQuery chan, queryString
Set output = Worksheets("Sheet1").Range("A1")
SQLRetrieve chan, output, , , True
SQLClose chan


Show: