Article ID: 117644
Article Last Modified on 10/11/2006
SQLRetrieve(ConnectionNum, DestinationRef, MaxColumns, MaxRows,
ColNamesLogical, RowNumsLogical, NamedRngLogical,
FetchFirstLogical)
When you execute the SQLRetrieve command with the argument
"NamedRngLogical" set to TRUE, the column names in the result set will
always be defined on the active workbook regardless of what the
"DestinationRef" argument is set to. If no workbooks are active when you
run the SQLRetrieve command, and if "NamedRngLogical" is set to TRUE, you
will receive the #N/A error value; however, the records will still be
retrieved to the range specified by destination.
Sub GetData()
' To define the ranges for the column names in the workbook to
' which the data is returned, use the following macro:
Dim DestRange As Object
Dim Chan, NumCols, NumRows As Variant
Dim i As Integer
Set DestRange = ThisWorkbook.Sheets("Sheet1").Range("A1")
Chan = SQLOpen("DSN=NWind;FIL=dBase4;")
' Enter the following statement on a single line.
NumCols = SQLExecQuery(Chan, "SELECT customer.CONTACT, " & _
"customer.COMPANY FROM customer.dbf")
NumRows = SQLRetrieve(Chan, DestRange, , , True)
SQLClose(Chan)
DestRange.Resize(NumRows + 1, NumCols).CreateNames Top:=True, _
Left:=False
End Sub
Additional query words: 5.00a 5.00c XL
Keywords: kbcode kbhowto kbprogramming KB117644