Results 1 to 11 of 11
  1. #1
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18

    VBA to save report view as PDF

    Hi there,



    I have a Report that runs from a Query, query looks for existing records (ID), then displays them on screen. Report just puts the Query in a nice presentable way (formatting). I am still coding, but the idea is to have the report to be able to run by user (no ribbons, no commands, no controls, just the report button to open/run it). That being said, When the report is run, it calls the query, parameter popup comes up, I entered the value and I get the values on screen with a command button I added to the Header. I thought it was as simple as:

    Private Sub Command13_Click()


    DoCmd.OutputTo acOutputReport, "test", acFormatPDF, "c:\OF_test.pdf"

    End Sub


    but everytime I run it (click command button), it always gets the error 2501, The OutputTo action was canceled, any ideas??


    Many 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,518
    In later Windows versions, you may not have write permissions to the root. I use a folder off the root where I know I have write permissions.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    Quote Originally Posted by pbaldy View Post
    In later Windows versions, you may not have write permissions to the root. I use a folder off the root where I know I have write permissions.

    I have writing permissions on any folder in this machine... I have also tried a different path (my desktop) and still same error....

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Will the report open directly from the navigation pane?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    Quote Originally Posted by pbaldy View Post
    Will the report open directly from the navigation pane?
    If I take the code out, report will open fine, when I include the code, report opens fine, and when I click the button I get the error...

  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,518
    Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    I got it to work, for some reason I had to be very explicit in the code:

    DoCmd.OutputTo objecttype:=acOutputReport, Objectname:="test", outputformat:=acFormatPDF, Outputfile:="C:\OF_Test.pdf", autostart:=True, outputquality:=acExportQualityPrint

    now the issue is how to save it to the user's Desktop, I have tried to use variables:

    RName = "OF_" & Format(Now(), "MM-DD-YY") & ".pdf"
    RPath = "%USERPROFILE%\Desktop"
    RSaveas = RPath & RName

    DoCmd.OutputTo objecttype:=acOutputReport, Objectname:="test", outputformat:=acFormatPDF, Outputfile:=RSaveas, autostart:=True, outputquality:=acExportQualityPrint

    but it crashes again with the same error, 2501

    any ideas?

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Untested, but you'd need a backslash after Desktop.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    This worked for me:

    DoCmd.OutputTo acOutputReport, "Compensation", acFormatPDF, "C:\Users" & Environ("USERNAME") & "\Desktop\tst.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.

  10. #10
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    yes, thanks... I was about to try Environ("username") and it worked fine... thanks

  11. #11
    jairgarza is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2017
    Posts
    18
    Quote Originally Posted by pbaldy View Post
    Untested, but you'd need a backslash after Desktop.
    I had it but for some odd reason it didn't want to be cc'd here (?)... thanks!

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

Similar Threads

  1. Replies: 2
    Last Post: 07-15-2015, 08:35 PM
  2. New report in design view will not save.
    By khughes46 in forum Reports
    Replies: 2
    Last Post: 02-11-2015, 01:34 PM
  3. Replies: 15
    Last Post: 01-28-2014, 12:20 PM
  4. Replies: 1
    Last Post: 06-28-2012, 09:57 AM
  5. Replies: 10
    Last Post: 06-20-2012, 09:50 AM

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