PDA

View Full Version : Solved: Using DoCMD to Open Report in Loop gives error



laptoprob
02-23-2006, 02:39 PM
My Database uses VB to update 3 tables using SQL when I select a Print Report button on my Form. Pressing one of 20 print Report buttons runs the SQL code to update these tables and then calls the "DoCmd.OpenReport stDocName, acViewPreview" to open the report and allow me to confirm the printout after viewing the report. This works fine on its own.
I have added an extra button that will loop through the code and call up each report from 1 to 20 the same as pressing the buttons. The problem is that as soon as the first report is generated and opened, the code then goes to generate the second report but has not got access to the three tables that are used by the Report and gives an error saying an other user or program is using the tables so it cannot update them. My report is the same report that is called up and always uses the same tables, the data in the tables though is changed by the VB code before the report is opened. Can anyone tell me how I can make the Subroutine wait until the Report has released the tables before it continues to update them to stop the error. I do not want to generate 20 different sets of tables and have 20 versions of the same report calling up the tables. Any Help / Suggestions will be appreciated. Thanks..

Norie
02-23-2006, 02:50 PM
Why not close the reports before opening the next one?

matthewspatrick
02-23-2006, 04:07 PM
I would have each report extracted out to Snapshot or PDF and then closed before moving on to the next...

laptoprob
02-24-2006, 09:02 AM
Got it sorted thanks, Used "acViewNormal" to send printouts direct to printer and the "DoCmd Close acReport" after it. I still use the "acViewNormal" for viewing a single Report before sending to printer.