Article ID: 157090
Article Last Modified on 11/23/2006
Dim qTbl As QueryTable
Sub CreateQueryTable()
'Create a new query table.
Set qTbl = ActiveSheet.QueryTables.Add("ODBC;dsn=Northwind", _
ActiveSheet.Range("A1"), Sql:="Select * from Customers")
'Refresh the query table.
qTbl.Refresh BackgroundQuery:=False
'Display the number of rows returned to the query table.
MsgBox qTbl.ResultRange.Rows.Count & " Rows Returned"
End Sub
Dim qTbl As QueryTable
Sub CreateQueryTable()
'Create a new query table.
Set qTbl = ActiveSheet.QueryTables.Add("ODBC;dsn=Northwind", _
ActiveSheet.Range("A1"), Sql:="Select * from Customers")
'Refresh the query table in the background.
qTbl.Refresh BackgroundQuery:=True
'Run the procedure to loop until the query is refreshed.
CheckQueryRefreshState
End Sub
Sub CheckQueryRefreshState()
If qTbl.Refreshing Then
'If the query is still refreshing, call the
'CheckQueryRefreshState again in one second.
Application.OnTime Now() + TimeValue("00:00:01"), _
"CheckQueryRefreshState"
Else
'Display the number of rows returned to the query table
'after the query table is refreshed.
MsgBox qTbl.ResultRange.Rows.Count & " Rows Returned"
End If
End Sub
Dim qTbl As QueryTable
Sub CreateQueryTable()
'Create a new query table.
Set qTbl = ActiveSheet.QueryTables.Add("ODBC;dsn=Northwind", _
ActiveSheet.Range("A1"), Sql:="Select * from Customers")
'Refresh the query table in the background.
qTbl.Refresh BackgroundQuery:=True
'Loop and wait until the query is refreshed.
Do While qTbl.Refreshing
DoEvents
Loop
'Display the number of rows returned to the query table.
MsgBox qTbl.ResultRange.Rows.Count & " Rows Returned"
End Sub
Additional query words: XL97
Keywords: kbdtacode kbprogramming KB157090