Form events not triggering during printing and PDF export?

illarion

New member
Local time
Today, 15:04
Joined
Sep 21, 2015
Messages
4
Hi all, tearing my hair out over this, really hope someone can point me in the right direction. My application uses reports which do a fair bit of work in VBA. Among other things, they run some additional queries to populate embedded Excel charts. As reports, these work fine, but the customer has now decided they want their users to be able to edit the report output at the point of printing. I couldn't think of any way of doing this other than displaying the data on a form rather than a report, so that's what I did, and it's very close to working. The form shows the data, including the graphs, the VBA code works correctly, and the data is editable. All so far, so good. Until I come to print. The VBA code is mostly in the form_current event, which seems most closely analagous to the detail_print of the reports. Works fine in normal view. But it seems that form_current doesn't get called either when printing, or when exporting to PDF, so the graphs don't work in either of those cases, which is a total dealbreaker. What can I do? Is there an event I can use instead of form_current, that fires during printing and PDF export, per record? Is there another way to approach this? All advice very much appreciated.
 
your method is correct of using the form.
IF NO code is running during the print,:
1. there really shouldnt be a lot of code needed during a report. The query does all the work. At most, I have had 2 or 3 lines of code in a report to 'paint' fields.

2. Its possible your code is 'turned off'. So look in the Access options and make sure ENABLE ALL MACROS / CODE is on. sometimes its off and nothing works.
 
Last edited:
Thanks Ranman.
1 - The way the reports are setup, there is a fair bit of code needed, primarily as I mentioned to populate and configure the embedded Excel chart objects (the built in charts in Access not being sufficient for requirements). Those charts are being populated with the results of other queries.
Even if that's not the ideal way to approach the problem, it would be an infeasibly large job to change them now.

I need to get that code running, or worst case, get a definitive "you absolutely cannot do what you are trying to do".

2 - The code executes just fine in "normal" form view. I'm not actually aware of a setting that disables code other than "Use Access special keys", but code is running just fine throughout the rest of the application, which is mostly VBA.
 
Print and Output to PDF are completely different beasts
 
Can you elaborate on that? If, for example, there is an event that will work for me while printing, I can print to a pdf "printer" and sidestep the issue with export to PDF.
 
It might be a timing issue. you probably need to save the edited data before you run the report.

the changes will be held in record buffers until then.
 
Probably a not too helpful answer but if you do something along the lines of:
Code:
DoCmd.OutputTo acOutputReport, "Report", "PDFFormat(*.pdf)", , True, , , acExportQualityPrint
you start off thinking this will print to PDF but is an entirely different function.

I parked this some time ago as it was not urgent but suspect that a lot of your code is actioned at time of print preview and therefore a simple vba approach bypasses this and loses all your actions, the same is probably the case with a vba print function.
 
Thanks for the responses all, you got me started thinking in a different direction, and I have solved my issue. :)
 

Users who are viewing this thread

Back
Top Bottom