?
Solved

VBA Code Does't Execute When Exporting to PDF

Posted on 2014-02-02
6
Medium Priority
?
658 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

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 25

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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