?
Solved

Programatically renaming reports when printing to .pdf

Posted on 2005-05-11
5
Medium Priority
?
348 Views
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?

Thanks,

TomAlford
0
Comment
Question by:TomAlford
3 Comments
 
LVL 19

Expert Comment

by:Eric Sherman
ID: 13980781
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
 

Author Comment

by:TomAlford
ID: 13982104
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
 
LVL 4

Accepted Solution

by:
d_a_h earned 1000 total points
ID: 13984399
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

Featured Post

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.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
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.
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…

809 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