Using VBA, I can easily open a report based on a query. I normally want to open the report simply to print it, rather than to view it on the screen.
Sometimes I use a WHERE clause to limit the data in the report. When I use a WHERE clause, I want to change a label in the PageHeader to show what the limit (the filter) is. E.g., for one WHERE clause, the label caption might need to show, "Students for Teacher Jane Doe," and for another WHERE clause, "Students for Techer John Smith."
I use this code to open the report:
docmd.OpenReport "rpt_R010_StudentListing", acviewNormal,,"lngTeacher=5".
If I open the report this way, no events trigger and the report simply prints without the necessary change in the label caption.
If I open the report using acViewPreview, however, events trigger in the report, and I can easily change the label caption. For example, on PageHeader.Format event, I can say, "lblPageHeader.Caption = 'Students for Teacher Jane Doe.'"
Because I'm developing this process for other users, I don't want a preview of the report; instead I simply want to print it directly.
Am I doing something wrong? Or do I need a work-around? If I need a work-around, can anyone provide any suggestions?