UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Field Information Disappears In Print Preview, Access 2016    
 
   
VariableZ
post Jul 10 2019, 10:18 AM
Post#1



Posts: 7
Joined: 29-July 11



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.
Go to the top of the page
 
theDBguy
post Jul 10 2019, 10:29 AM
Post#2


Access Wiki and Forums Moderator
Posts: 75,708
Joined: 19-June 07
From: SunnySandyEggo


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...

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
VariableZ
post Jul 10 2019, 12:41 PM
Post#3



Posts: 7
Joined: 29-July 11



Thank you for pointing me in the right direction! For posterity's sake, here's what I did:
  • The code was originally in the report's On Load event.
  • I copied the code to the header's On Format event, so if the user clicked Print Preview, the field values would still be there in the print preview.
  • Unfortunately, when the user clicked Close Print Preview, the fields were blank again.
  • I tried the On Paint event, but while that technically worked, it also - obviously in retrospect - resulted in a perpetual loop where every time the code ran, it set up the condition where it needed to run again.
  • Finally, it occurred to me to put the code in the report's On Got Focus event, and that fixed it.

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.
This post has been edited by VariableZ: Jul 10 2019, 01:18 PM
Go to the top of the page
 
theDBguy
post Jul 10 2019, 01:22 PM
Post#4


Access Wiki and Forums Moderator
Posts: 75,708
Joined: 19-June 07
From: SunnySandyEggo


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

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
VariableZ
post Jul 10 2019, 02:12 PM
Post#5



Posts: 7
Joined: 29-July 11



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.
Go to the top of the page
 
theDBguy
post Jul 10 2019, 02:35 PM
Post#6


Access Wiki and Forums Moderator
Posts: 75,708
Joined: 19-June 07
From: SunnySandyEggo


Interesting... Thanks for the update.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    16th July 2019 - 06:13 PM