Naming a PDF File (1 Viewer)

Learn2010

Registered User.
Local time
Today, 14:55
Joined
Sep 15, 2010
Messages
415
I have a form that is being filled in (Access 2013). When completed, the click event of a button on the form when clicked creates a PDF file using the following:

START OF CODE

DoCmd.OutputTo acOutputReport, "rptCustomer", _
acFormatPDF, "C:\Intake\PDFs\GetSignature.pdf"


END OF CODE

The PDF file is being named GetSignature. It will be saved with the CustomerID as part of the name. CustomerID is a field in the form. I would like to name the form with the CustomerID instead of naming it GetSignature. For instance, CustomerID is 12345. I want the file to be named 12345.

What do I need to change to do that?

Thank you.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:55
Joined
Sep 21, 2011
Messages
14,264
Try
Code:
DoCmd.OutputTo acOutputReport, "rptCustomer", _
acFormatPDF, "C:\Intake\PDFs\" & Me.CustomerID & ".pdf"
 

Learn2010

Registered User.
Local time
Today, 14:55
Joined
Sep 15, 2010
Messages
415
That worked. Thanks.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 14:55
Joined
Feb 19, 2002
Messages
43,257
I see you have an answer but I would use something more meaningful should you ever need to export a different file.

Code:
DoCmd.OutputTo acOutputReport, "rptCustomer", _
acFormatPDF, "C:\Intake\PDFs\GetSignature_" & Me.CustomerID & ".pdf"
 

Lightwave

Ad astra
Local time
Today, 19:55
Joined
Sep 27, 2004
Messages
1,521
I use this quite a lot to print multiple individual PDFs
It loops through the records in a query and prints all to a directory and names them something meaningful in this case an index based on an id. Which is exactly in line with Pat H's comment.

Where the fields in the QUERY-ListofIDtoPrint includes ID / Field02 / Field03 / Field04

Its' useful if you are administering a system or users need to print a report on multiple reports regularly

Code:
Public Function LoopandPrint()

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim MyFileName As String
Dim mypath As String

mypath = "C:\Data\EXPORTdirectory\"

Set db = CurrentDb()
Set rs = db.OpenRecordset("QUERY-listofIDtoPrint")

Do While Not rs.EOF

MyFileName = rs!ID & "-" & rs!Field02 & "-" & rs!Field03 & "-" & rs!Filed04 & ".pdf"

'MsgBox MyFileName

DoCmd.OpenReport "R001TargetReport", acViewPreview, , "[PlanAppID]=" & rs!ID
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "R001TargetReport"

rs.MoveNext
Loop

Set rs = Nothing
Set db = Nothing

End Function
 

Learn2010

Registered User.
Local time
Today, 14:55
Joined
Sep 15, 2010
Messages
415
Thanks for the added info. I will use it carefully.
 

Users who are viewing this thread

Top Bottom