Results 1 to 5 of 5
  1. #1
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593

    Save a Report as a pdf.

    Hi,

    I'm trying to save a report to my Desktop as a pdf - adding a date {that I am retrieving from a query} as part of the pdf file name.
    I get a
    Run-time error '2501' - The OutputTo action was cancelled.
    (See screenshot).

    Here's the code I'm using. So far - all I've tried to do is run the function from the Visual Basic Editor.
    Code:
    Function SaveReport()
    
    Dim strSQL As String
    Dim strPath As String
    Dim strFilename As String
    
    'Get the ReportDate.
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    DoCmd.SetWarnings False
    
    Set db = CurrentDb
    strSQL = "SELECT Min([VPNDate]) AS ReportDate FROM QryVPN_Forensics_SessionID"
    Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot)
    
    'Set up the Path & File names.
    strPath = "C:\Documents and Settings\rsengupta\Desktop\"
    strFilename = strPath & "VPN_Forensics_Report_" & CStr(rs![ReportDate]) & ".pdf"
    
    'Save The Report {this is where the code errors}.
    DoCmd.OutputTo acOutputReport, "VPN_Forensics_SessionID", acFormatPDF, strFilename, False
    
    End Function
    I've googled and tried some suggestions - but I still get this error.

    I'd appreciate any help I can get.



    Thanks!!
    Attached Thumbnails Attached Thumbnails SaveReport_Error.JPG  

  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,652
    My guess is that the date portion is including slashes, which would be an invalid file name. You can check when it's in debug mode. I'd use the format function to make sure it's in the desired format. Typically I use yyyymmdd which makes it sort properly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593
    Thanks, Paul!

    Yes - I just noticed that and changed it and came back in to say I'd figured it out - when I saw your response.
    Appreciate your help - as always!

    I made this change in my code:
    Code:
    MyFilename = MyPath & "VPN_Forensics_Report_" & CStr(Format((rs![ReportDate]), "yyyy-mm-dd")) & ".pdf"
    Works fine now.

  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,652
    No problem. By the way, the CStr() is unnecessary, as the Format() function returns a string anyway. It's not hurting anything, but it's not doing anything either.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593
    Thanks! I'll take that out.

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

Similar Threads

  1. Replies: 10
    Last Post: 06-20-2012, 09:50 AM
  2. Report changes will not save
    By phyllisgirl in forum Reports
    Replies: 4
    Last Post: 05-07-2012, 09:28 PM
  3. Replies: 6
    Last Post: 12-12-2011, 09:57 PM
  4. Save Report in Attachment
    By A S MANN in forum Queries
    Replies: 1
    Last Post: 10-08-2010, 08:33 PM
  5. Save report as pdf.
    By sams in forum Reports
    Replies: 7
    Last Post: 05-11-2010, 09:20 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