Results 1 to 6 of 6
  1. #1
    jennifers is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2019
    Posts
    19

    Dynamic Report File Name When Saving as PDF?

    I have found a way to change the report caption dynamically based on criteria in the report and this only changes the file name for email purposes. I would like the default save as PDF report name to be dynamic based on report criteria. What is the best way to do so?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,522
    report name is picked in a combo box
    the query holds the Output title. the query knows who and what.


    vTitle = me.txtTitle
    vFile = "c:\temp" & vTitle & ".pdf"
    'this web site keeps removing the slash after TEMP)

    DoCmd.OutputTo acOutputReport, cboRpt, acFormatPDF, vFILE

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I don't know about "best"; I typically use OutputTo to save the file with the desired name.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    jennifers is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2019
    Posts
    19
    This may be a novice question but where is the correct place to put the VTitle = and the vFile= ? I get "Compile Error: Variable not defined". I was trying to put i t in the on click event for print preview.

  5. #5
    jennifers is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Sep 2019
    Posts
    19
    I was able to add a button to my form that generates the report to solve this and save it as a PDF with the name containing the criteria. Here was my solution:

    Dim StrFileName As String
    Dim strReport As String
    Dim strFrmDate As String
    Dim strToDate As String


    strReport = "My Report Name"
    strFrmDate = Format(Me.txtFromDate, "MM-DD-YYYY")
    strToDate = Format(Me.txtThruDate, "MM-DD-YYYY")


    StrFileName = Me.cboReport & " " & Me.cboUnitNum.Column(2) & "_" & strFrmDate & "-" & strToDate & ".PDF"
    StrFileName = "C:\Data\temp" & StrFileName


    DoCmd.OpenReport strReport, acViewPreview


    DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, StrFileName, False

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad you got it working. You generally don't need to open the report first, unless you're using a wherecondition to filter it. You might try it without that line to get rid of the user seeing it, unless of course you want them to.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 04-01-2016, 10:38 AM
  2. Replies: 3
    Last Post: 04-22-2015, 04:35 AM
  3. Saving report IDs to a text file
    By Ruegen in forum Programming
    Replies: 3
    Last Post: 12-16-2013, 09:19 AM
  4. Dynamic/Variable Image File on Report
    By JoeM in forum Reports
    Replies: 5
    Last Post: 02-26-2013, 06:59 AM
  5. Replies: 21
    Last Post: 01-24-2012, 06:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums