PDA

View Full Version : delay between codes



ThaNguyen
07-09-2008, 11:31 AM
I have a small macros that have a couple subs that run together. Here is a sample

Sub daily()
Application.Run "Sales.xls!SalesQuery" -
'Query the sales data based on the criteria entered

Application.Run "Sales.xls!AddToRecord"

End sub

The problem when run the second macros (Application.Run "Sales.xls!AddToRecord") will execute before the SalesQuery is complete.

I used the Application.Wait Now() + TimeValue("00:05:00") between the two codes and it does not work.

Is there a way to make the query is done before execute the next code?

Any help ideas would be greatly appreciated

Thanks

ThaNguyen
07-09-2008, 11:45 AM
This is the error

This action will cancel a pending Refresh Data command. Continue?

ThaNguyen
07-09-2008, 01:00 PM
Found the answer after a few hour searching all I need to do was to add .BackgroundQuery = False in part of the code.