Programatically renaming reports when printing to .pdf

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?

Thanks,

TomAlford
TomAlfordAsked:
Who is Participating?
 
d_a_hCommented:
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)
0
 
Eric ShermanAccountant/DeveloperCommented:
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"
Wend

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

ET

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

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

All Courses

From novice to tech pro — start learning today.