Output to PDF doesn't "run" .Visible (1 Viewer)

chuckcoleman

Registered User.
Local time
Today, 02:50
Joined
Aug 20, 2010
Messages
357
Hi, I have a report that has on the "On Load" event some code that makes a text box visible or not based on some criteria. It works perfectly when you open the report using Print Preview. When I click on a Command Button that runs code and then exports the report to a PDF, the .visible doesn't work for the text box. The text box is not shown in the PDF even though the criteria on the form was there when I clicked on the Command Button. My guess is that because the report isn't opened, (loaded), the code never runs to make the text box visible or not.

Any ideas?

Thanks, Chuck
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:50
Joined
Aug 30, 2003
Messages
36,118
You can use OpenReport to open the report, you can make it invisible. Then export with OutputTo, then close the report.
 

Isaac

Lifelong Learner
Local time
Today, 00:50
Joined
Mar 14, 2017
Messages
8,738
Just adding another thought

I rarely use Access reports but I think I have heard that there is a Format or OnFormat event - and this might be the event you want to use for things that must be reflected in a printout.
 

bastanu

AWF VIP
Local time
Today, 00:50
Joined
Apr 13, 2010
Messages
1,401
To programmatically manipulate the visibility of controls in reports you need to use the Format or Print events of the section containing the specific controls. Alternatively you can try to do it using conditional formatting (to make a control content invisible create a formatting rule to set its fore colour the same as its backcolour).
Cheers,
 

chuckcoleman

Registered User.
Local time
Today, 02:50
Joined
Aug 20, 2010
Messages
357
All, thank you. The easy solution was to move my code from On Load to the Format section of a Section. That worked.

Thank you!

Chuck
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:50
Joined
Feb 28, 2001
Messages
27,001
Just as a follow-up, turns out that reports have TWO event paths. If you are displaying the report, you use OnFormat. If you are printing the report (which might be inferred from being in Print Preview mode), you use OnPrint. They are mutually exclusive.
 

chuckcoleman

Registered User.
Local time
Today, 02:50
Joined
Aug 20, 2010
Messages
357
The_Doc_Man, For What It's Worth, I used the On Format event in the Report Footer, and it worked.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:50
Joined
Aug 30, 2003
Messages
36,118
Just as a follow-up, turns out that reports have TWO event paths. If you are displaying the report, you use OnFormat. If you are printing the report (which might be inferred from being in Print Preview mode), you use OnPrint. They are mutually exclusive.

In my experience, it's Report view that differs from Preview and Print.
 

Users who are viewing this thread

Top Bottom