Solved

VBA Code Does't Execute When Exporting to PDF

Posted on 2014-02-02
6
650 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

737 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