SQLBind Function

Description

In Microsoft Excel for Windows 95, do not use SQLBind 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.

SQLBind specifies where results are placed when they are retrieved using SQLRetrieve or SQLRetrieveToFile. Use SQLBind to change the column order of the result set from a query, or to place the result set columns in non-adjacent worksheet columns.

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 using the References command (Tools menu).

Syntax

SQLBind(connectionNum, column, reference)

connectionNum

Required. The unique connection ID of the data source, returned by SQLOpen, for which you want to bind results.

column

Optional. The column number of the result set that you want to bind. Columns in the result set are numbered from left to right starting with 1. If you omit column, all bindings for connectionNum are removed.

Column number 0 (zero) contains row numbers for the result set. You can return the row numbers by binding column number 0 (zero).

reference

Optional. The location of a single cell on a worksheet where you want the results bound, as a Range object. If reference is omitted, binding is removed for the column.

Return Value

This function returns an array listing the bound columns for the current connection by column number.

If SQLBind is unable to bind the column to the cell in the specified reference, it returns Error 2042.

If connectionNum is not valid or if you try to bind a cell that is not available, SQLBind returns Error 2015.

If reference refers to more than a single cell, SQLBind returns Error 2023.

If SQLRetrieve does not have a destination parameter, SQLBind places the result set in the location indicated by reference.

Remarks

SQLBind tells the ODBC Control Panel Administrator where to place results when they are received using SQLRetrieve The results are placed in the reference cell and cells immediately below it.

Use SQLBind if you want the results from different columns to be placed in disjoint worksheet locations.

Use SQLBind for each column in the result set. A binding remains valid as long as the connection specified by connectionNum is open.

Call SQLBind after calling SQLOpen and SQLExecQuery, but before calling SQLRetrieve or SQLRetrieveToFile. Calls to SQLBind do not affect results that have already been retrieved.

See Also

SQLClose Function, SQLError Function, SQLExecQuery Function, SQLGetSchema Function, SQLOpen Function, SQLRequest Function, SQLRetrieve Function, SQLRetrieveToFile Function.

Example

This example runs a query on the NWind sample database, and then it uses the SQLBind function to display only the fourth and ninth columns of the query result set (the product name and the quantity on order) on Sheet1.


If Application.OperatingSystem Like "*Win*" Then
    databaseName = "NWind"
Else        'Macintosh
    databaseName = "NorthWind"
End If
queryString = "SELECT * FROM product.dbf WHERE (product.ON_ORDER<>0)"
chan = SQLOpen("DSN=" & databaseName)
SQLExecQuery chan, queryString
Set output1 = Worksheets("Sheet1").Range("A1")
Set output2 = Worksheets("Sheet1").Range("B1")
SQLBind chan, 4, output1
SQLBind chan, 9, output2
SQLRetrieve chan
SQLClose chan