Auto-naming PDF Document

gcomp

Registered User.
Local time
Yesterday, 22:35
Joined
May 28, 2010
Messages
45
I have set up a macro that among other things outputs a report into PDF format. I set it up to automatically go to the correct directory where I could also put in a file name. Is it possible to have the file named automatically from a field in the report? Specifically I want the PDF file to be named the purchase order number which is one field in the report.
 
You'd have to get the field value somehow, but this type of thing (this is in 2007):

DoCmd.OutputTo acOutputReport, "rptBooking", acFormatPDF, "C:\Whatever\" & strFileName & ".pdf"

Where strFileName is a string containing your desired name. That could come from a form if appropriate, or a DLookup getting the value from the source query of the report.
 
I am using Access 2007, but I'm not quite sure how to do the string. The query name is POQuery and the field with the number I want as the pdf document name is Expr1. Can you help me out?
 
Try

Dim strFileName As String
strFileName = DLookup("Expr1", "POQuery")
DoCmd.OutputTo acOutputReport, "rptBooking", acFormatPDF, "C:\Whatever\" & strFileName & ".pdf"
 
I guess I'm having an "idiot" day. I trying to enter your suggestions into my macro where the action is to output to a pdf file. It asks for output filename. This is where I'm entering your suggestions. Is this the proper way or am I way off?
 

Users who are viewing this thread

Back
Top Bottom