Article ID: 142357
Article Last Modified on 10/11/2006
Sub UsingBuildSQL()
' Dimension the variables.
Dim s As Variant
Dim myrequest As Variant
Dim chan As Integer
' Initiate a channel to MSQuery.
chan = DDEInitiate("MSQuery", "System")
' Log on to the Nwind datasource.
DDEExecute chan, "[Logon('NWind')]"
' Execute a SQL statement.
DDEExecute chan, "[Open('Select * From Employee')]"
' Request the ODBC SQL statement in strings of 120 characters
' and places it into an array.
myrequest = DDERequest(chan, "ODBCSQLStatement/120")
' Execute the BuildSQL statement for each element returned.
For Each s In myrequest
DDEExecute chan, "[Buildsql('" & s & "')]"
Next
' Execute the SQL statement built by BuildSQL.
DDEExecute chan, "[QueryNow()]"
' Request the number of rows.
NumRows = DDERequest(chan, "NumRows")
' Request the number of columns.
NumCols = DDERequest(chan, "NumCols")
' Return the data to Sheet1.
DDEExecute chan, "[Fetch('Excel','Sheet1','R1C1:R" & NumRows(1) & _
"C" & NumCols(1) & "','All/Headers')]"
' Terminate the DDE channel.
DDETerminate chan
End Sub
BuildSQL
Additional query words: 5.00c 8.00 97 interoperability XL
Keywords: kbdtacode kbhowto kbprogramming KB142357