Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Access Reports _ Field Information Disappears In Print Preview

Posted by: VariableZ Jul 10 2019, 10:18 AM

I have a report with a bunch of fields that get their values from VBA code. When the report opens, the fields are all populated with data. If the user prints the report, the field data prints just like it's supposed to. But if the user clicks Print Preview, the field data disappears, and if the user then prints the report, the fields all print out blank. In fact, once Print Preview has been clicked, even though clicking Close Print Preview brings the user back to the original report view, the fields are still blank, and the only way to repopulate them is to close the report and open it again. Is there anything that can be done to allow the user to click Print Preview and actually see the report as it's supposed to be printed?

Note that this only happens to fields that get their values via VBA code, and it doesn't matter if the fields are in the Report Header, Page Header, of Body of the report.

The report is opened with a button using DoCmd.OpenReport and acViewReport. Interestingly, the field values show up just fine if the report is opened with acViewPreview instead of acViewReport, but because of the different printers that this report is printed on, I've found that opening with acViewPreview is not an option.

Any suggestions are welcome. Thank you.

Posted by: theDBguy Jul 10 2019, 10:29 AM

Hi. When using VBA to manipulate a report, we'll need to be aware some events don't fire depending on the view used when opening the report. You might experiment on that. For example, if you have your code only in the Print event, try also copying them into the Format event. Just a thought...

Posted by: VariableZ Jul 10 2019, 12:41 PM

Thank you for pointing me in the right direction! For posterity's sake, here's what I did:


The odd part of all of this is that several of my reports have similar code in the On Load event and nowhere else, yet they don't have this problem. It seems that there may be some code or setting in the report, or a conflict that I have yet to identify, that's causing this problem in just the one report. Hrmph.

Posted by: theDBguy Jul 10 2019, 01:22 PM

Hi. Glad to hear you found a way around the issue. Good luck with your project.

Posted by: VariableZ Jul 10 2019, 02:12 PM

The problem appears to be the Modal property of the report. When Modal is set to NO, fields can be set in the On Load event, and they don't change when going into or out of Print Preview. When Modal is set to YES, any field set in the On Load event gets cleared when going either into or out of Print Preview. I don't know why.

Posted by: theDBguy Jul 10 2019, 02:35 PM

Interesting... Thanks for the update.