• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 675
  • Last Modified:

VBA Code Does't Execute When Exporting to PDF

I have a report that contains underlying VBA code. The code hides and shows report objects based on various conditions. When I preview the report, the code executes as planned. When I export the report to PDF, my code doesn't execute. Is there any solution to this problem?
0
TechMommy
Asked:
TechMommy
1 Solution
 
chaauCommented:
What we do is instead of exporting to a PDF we print to a PDF printer. We also have a VBA code, and it works
0
 
TechMommyAuthor Commented:
Do you print to a PDF printer programmatically, or from the UI? In this application the process of exporting to PDF is executed from a VBA module. It all has to be automated.
0
 
chaauCommented:
We open the report and print it via a VBS script, that runs via the Task Scheduler. Yes, it is automated
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MacroShadowCommented:
Put your code in the Detail_Format sub-routine.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    ' Your code
End Sub

Open in new window

0
 
mbizupCommented:
Hi Alison,

This is similar to printing out or exporting a single record (or otherwise filtered records) in a report.

The catch is to open your report in Preview - so that the VBA code runs/ filtering takes place/ etc, and then use the outputTo command to export the report to PDF:

DoCmd.OpenReport "YourReport", acViewPreview
DoCmd.OutputTo acOutputReport, "YourReport", acFormatPDF, "YourFileName.PDF", True
doCmd.Close acReport, "YourReport"  ' <---  you can do this if the preview is not needed.

Open in new window

0
 
TechMommyAuthor Commented:
This solution works great and was simple to implement. I was able to implement and test it in 5 minutes!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now