Forum Discussion

Tony2021's avatar
Tony2021
Iron Contributor
Dec 24, 2021
Solved

Print Report to PDF and append Date to file name

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

 

  • you can Format$() the Date/Time:

    "C:\Users\Me\OneDrive\Documents\" & "Pending" + Format$(Now(), "yyyymmdd") & ".pdf"

2 Replies

  • arnel_gp's avatar
    arnel_gp
    Iron Contributor
    you can Format$() the Date/Time:

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

Resources