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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report runs OnOpen event multiple times

Status
Not open for further replies.

burlymerly

Programmer
Apr 2, 2006
5
US
I have built a report for printing an invoice that mirrors our printed 4 part hardcopy. Page 1, Page2, etc. with only one label different to indicate where each page should be distributed (i.e. customer, field office, main office...).

I built page 1 first, then copied and pasted this report 3 more times. Each copy was then edited to change the label file. I then added these subreports to page 1 with page breaks between.

All has been working well, but today I have added some qualifying code (to determine which RecordSource should be used, depending on which form calls the report) to the OnOpen event of the report. I now find that the page 1 OnOpen event runs once as it should, but the remaining subreports OnOpen events run multiple times.

Any ideas on how to track down the reason for this behavior? Is this approach wrong? Is there a better way?

Thanks for your help in advance
 
Hi, burlymerly,

Why complicate things with subreports? Why not just use multiple pages on the main report? In fact, since the only difference is a single label control, I think you could probably write a little VBA routine that would print all the copies and change the label caption on the fly. Then you would only have one page and one OnOpen event to deal with. I'll tinker a bit and see what I come up with...

Ken S.
 
Duh, don't know why I didn't think of it immediately... If you're printing the report from a command button, you could just send the label caption as the openargs argument of the DoCmd.OpenReport command. Of course, you would need to have a DoCmd.OpenReport line for each instance of the report.

HTH,

Ken S.
 
Ken,

Thank you for responding. I may be able to make this work.

Historically, this report is opened in preview and then printed from the menu but there is no compelling reason for using the report to preview as all data is already on the form for viewing.

One issue with this is: I have recently added the capability to save a report to pdf format. This allows us to email these documents rather than ground mail. With all pages in one report/subreports, all pages are saved to one pdf file. So, either I have 4 pdf files for one report, or save only one page to pdf. I will think on this one for a while yet.

Thanks again for responding. Your help is awesome.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top