Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need to run code once query finished

Status
Not open for further replies.

ARCITS

Programmer
Apr 4, 2002
99
GB
I need to startup a workbook and initially run 2 queries.
I am doing this by

...
Workbook_Open()
RefreshAll
...

Once the refresh has finished I need to run some further code.
The problem I have is that I cannot successfully capture the moment when the last query has finished it's refresh.
I have looked into QuesryTable_AfterRefresh (code below) but this event is not being fired at all.

Private Sub QueryTable_AfterRefresh(Success As Boolean)
If Success
' Query completed successfully
Else
' Query failed or was cancelled
End If
End Sub

I also looked at the .refreshing property and put this in a repeating Do_While_Loop as per following example code ...

Do While Worksheet("ABC").QueryTable(1).Refreshing
Loop

' code to execute after refresh finished.

Can anyone offer any advice or proven solutions to this one.


Thnaks,
 
additional info

sorry forgot to mention the queries are running via MSQuery.
When the Do While Loop is running on the .refreshing operation MSQuery does not execute the query as though it is locked out? The program never exits the loop!


Thanks
 
Try:

Do While Worksheet("ABC").QueryTable(1).Refreshing
DoEvents
Loop
 
Wrap the query in a transaction and check that the transaction is complete?

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top