SOLVED

Print Report to PDF and append Date to file name

Regular Contributor

Hello, I want to add a date in YYYYMMDD format to the file name below.  I cant seem to get it to work.  

the file name should be Pending 20211223.pdf

the below code is not correct (bold part)

 

Private Sub cmdExport_Click()
DoCmd.OutputTo acOutputReport, Me.Name, acFormatPDF, "C:\Users\Me\OneDrive\Documents\" & "Pending" + DateTime.Now.pdf, True, "", 0
End Sub

 

thank you

 

2 Replies
best response confirmed by Tony2021 (Regular Contributor)
Solution
you can Format$() the Date/Time:

"C:\Users\Me\OneDrive\Documents\" & "Pending" + Format$(Now(), "yyyymmdd") & ".pdf"
perfect. Works great. thanks again! happy holidays....