Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default Pause code for data return

I currently have several worbooks that run queries against a database and
create reports. I want to open and loop through the workbooks using another
workbook to open and run a grouped reporting macro. Data is brought into
Excel by the statement " With
ActiveSheet.QueryTables.Add(Connection:=ConnectStr ing,
Destination:=Range(DataTarget), Sql:=mySQL)
.Refresh (BackgroundQuery = False)
End With"
This is a part of a three step grouped code (GetData, CreateReports,
PublishReports). The CreateReports code does not wait for the data to return.
How can I force the code to pause during this data return?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Pause code for data return

QueryTables have a Refreshing property to let you know if they are still
refreshing, so a loop like the one below can pause until results are returned:

While MyQueryTable.Refreshing
DoEvents
Wend

This is bare-bones; I usually add a time-out period and you can also add
checks of the system status to prevent getting stuck in an endless loop. The
DoEvents ensures that your code is not hogging the processor!

"Candyman" wrote:

I currently have several worbooks that run queries against a database and
create reports. I want to open and loop through the workbooks using another
workbook to open and run a grouped reporting macro. Data is brought into
Excel by the statement " With
ActiveSheet.QueryTables.Add(Connection:=ConnectStr ing,
Destination:=Range(DataTarget), Sql:=mySQL)
.Refresh (BackgroundQuery = False)
End With"
This is a part of a three step grouped code (GetData, CreateReports,
PublishReports). The CreateReports code does not wait for the data to return.
How can I force the code to pause during this data return?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Pause code for data return

BackgroundQuery is the parameter which tells the querytable to wait while
refreshing.

You've specified it, but you have a syntax error.
Try:
..Refresh BackgroundQuery:=False

To avoid this type of bug in the futu from VBA Tools menu, select
Options. Tick the "Require Variable Declaration" box. It adds Option
Explicit to the top of code modules.


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Candyman" wrote in message
...
I currently have several worbooks that run queries against a database and
create reports. I want to open and loop through the workbooks using
another
workbook to open and run a grouped reporting macro. Data is brought into
Excel by the statement " With
ActiveSheet.QueryTables.Add(Connection:=ConnectStr ing,
Destination:=Range(DataTarget), Sql:=mySQL)
.Refresh (BackgroundQuery = False)
End With"
This is a part of a three step grouped code (GetData, CreateReports,
PublishReports). The CreateReports code does not wait for the data to
return.
How can I force the code to pause during this data return?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Pause during Dialog Box data entry kayabob Excel Discussion (Misc queries) 6 October 20th 05 02:58 PM
getting VBA to pause while external data loads from web vladiator Excel Programming 4 August 10th 04 11:09 PM
Pause Macro to enter data in cell Frank Kabel Excel Programming 4 May 30th 04 10:56 PM
Pause Macro to enter data in cell Bob Phillips[_6_] Excel Programming 0 May 28th 04 04:41 PM
Code to return the data a chart is based on dracstorey Excel Programming 3 January 18th 04 08:48 PM


All times are GMT +1. The time now is 05:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"