Solved

VBA Code Does't Execute When Exporting to PDF

Posted on 2014-02-02
6
633 Views
Last Modified: 2014-02-04
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
Comment
Question by:TechMommy
6 Comments
 
LVL 24

Expert Comment

by:chaau
ID: 39828811
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
 
LVL 11

Author Comment

by:TechMommy
ID: 39828820
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
 
LVL 24

Expert Comment

by:chaau
ID: 39828825
We open the report and print it via a VBS script, that runs via the Task Scheduler. Yes, it is automated
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 26

Expert Comment

by:MacroShadow
ID: 39828858
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
 
LVL 61

Accepted Solution

by:
mbizup earned 300 total points
ID: 39829171
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
 
LVL 11

Author Closing Comment

by:TechMommy
ID: 39834278
This solution works great and was simple to implement. I was able to implement and test it in 5 minutes!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now