Results 1 to 8 of 8
  1. #1
    davem05 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    9

    Report to .pdf with field values in filename

    Hi,
    I have cobbled together some code to 1) open a report based on a query, 2) save the report,


    The trouble I am having is using a text box value from the report as part of the filename.
    Here is the code I am currently using

    Code:
    Function Macro2()
    
    
    Dim myPath As String
    Dim strReportName As String
    
    
        DoCmd.OpenReport "Results Certificate 2", acViewReport, "", "", acNormal
    
    
    myPath = "C:\Users\Dave\desktop\"
    strReportName = ![labNumber] & ".pdf"
    
    
        DoCmd.OutputTo acOutputReport, "Results Certificate 2", acFormatPDF, myPath & strReportName, False
        DoCmd.Close acReport, "Results Certificate 2"
    
    
    
    
    End Function
    it is the strReportName = labNumber which I am having problems with.
    This is based on a text box called "labNumber", from a table called "Cat Details" if that is required.
    Without that line the rest of works fine.

    I have tried various ways of representing it from searches i have preformed over several hours, but nothing has solved it.

    Any help at all would be hugely appreciated.
    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Presuming it's on the report, try:


    strReportName = Reports![Results Certificate 2]![labNumber] & ".pdf"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Looks like what I do and it works.

    Differences in my code:

    1. open report in acViewPreview

    2. omit the report name in the OutputTo so it just uses the open report

    3. open report filtered with the WHERE argument of OpenReport
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    davem05 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2013
    Posts
    9
    Thank you!
    This worked, looking back through my previous attempts I had something very similar but it seems I had omitted the "s" from "Reports"
    Once again, thank you!!

    Quote Originally Posted by pbaldy View Post
    Presuming it's on the report, try:


    strReportName = Reports![Results Certificate 2]![labNumber] & ".pdf"

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The code is behind the report and report has the labNumber? Me alias should work although code should have worked without any qualifier prefix.

    Me![labNumber] & ".pdf"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The code opens the report, so presumably is not behind it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Then if LabNumber is on the form, the Me alias should still work and so should have the code without prefix. So maybe the code is actually in a public module.

    Macro2 is a poor name for a procedure. OutputPDF would be better.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Display the Filename in a Report.
    By GordonT in forum Access
    Replies: 1
    Last Post: 01-27-2013, 08:35 AM
  2. Replacing many values at once in a multiple values checkbox field.
    By ConfusedDatabaseDesigner in forum Forms
    Replies: 2
    Last Post: 07-20-2012, 08:58 AM
  3. Variuse FileName When Export
    By shay in forum Import/Export Data
    Replies: 1
    Last Post: 12-01-2010, 11:36 AM
  4. Replies: 1
    Last Post: 01-26-2010, 10:36 PM
  5. Replies: 0
    Last Post: 06-11-2009, 01:54 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