Programatically renaming reports when printing to .pdf

Posted on 2005-05-11
Last Modified: 2008-01-09
I have an application designed to generate reports to .pdf and automatically e-mail them. I am using pdf995 as the PDf function which allows you to pass it the report name. When Access prints to the pdf driver it uses the Caption control as the Printed document name. As long as I preview the report first, I can set the caption to whatever i want in the OnOpen function and when I print it it creates the correctly named file. However, if I print directly without previewing it first, the default report name is used. As an example, I have a report called "Dist_Sales_Report". If I want just western distributors, I run the report as "Dist_Sales_Report-WEST" and set the Caption in the report as that. When I run it in preview, the report shows "Dist_Sales_Report-WEST" and when I print it the .pdf generated is the same. If I just print without previewing, the .pdf generated file is "Dist_Sales_Report". Any suggestions?


Question by:TomAlford
    LVL 19

    Expert Comment

    by:Eric Sherman
    This is how I print my Access reports to a PDF driver then rename the report before attaching it to a email message.

    DoCmd.OpenReport "WorkOrderRpt", acViewNormal

    'Check to see if the file already exist and if so delete it.  
    If Dir("C:\Temp\WorkOrder.PDF") <> "" Then
         Kill "C:\Temp\WorkOrder.PDF"
    End If
    While Dir("C:\Temp\WorkOrder.PDF") = ""
         Name "C:\Temp\DefaultReportName.PDF" As "C:\Temp\WorkOrder.PDF"

    I then take the renamed file and attach it to an Outlook email message.



    Author Comment

    Thanks ET. I know this is one method but I am trying to prevent having to do it if Access can handle it automatically.

    LVL 4

    Accepted Solution

    I use Win2PDF (Dane Prairie) and the code for them is:

    SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", "C:\pathname\filename.pdf"
    DoCmd.OpenReport "Report Name"

    With this you can also do:

    strPath = "C:\pathname\filename"
    strLoc = "West"
    SaveSetting "Dane Prairie Systems", "Win2PDF", "PDFFileName", strPath & strLoc & ".pdf"
    DoCmd.OpenReport "Report Name"

    Basicaly, look at the docs / website of your PDF writer and see if you can find code similar to above, then you can fully automate (its what I do, each database produces >500 pdf's from 3 reports by looping and printing by department)

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    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…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

    728 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

    19 Experts available now in Live!

    Get 1:1 Help Now