Results 1 to 7 of 7
  1. #1
    buck is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    26

    Macro of VBA to Export Report as PDF

    Can anyone advise please how to export a Report as PDF in 2010 either Macro or VBA is fine.

    Thanks

    Cross-posted below




    http://www.mrexcel.com/forum/microsoft-access/746993-macro-export-pdf.html

  2. #2
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    Macro of VBA to Export Report as PDF

    Have a look into the OUTPUTTO function.

    Code:
    DoCmd.OutputTo acOutputReport, "rptREPORTNAME", acFormatPDF, strPathAndFile, True

  3. #3
    buck is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    26
    Hi Alex,


    I tried this a couple times prior to the post, but for some reason I'm getting run-time error 2501: outputto action was canceled. I tried a macro as well, but the outputto also canceled. Not sure if it matters, but the report source is a query with a date parameter. It opens fine and allows the date to be entered as it should, but the process then stops.

    I tried the strPathAndFile name with and without ""

    Private Sub Command22_Click()
    DoCmd.OutputTo acOutputReport, "rptLTR1RefundRequest", acFormatPDF, S:\Finance\Accounting\Overpayment-Collections\PENDING REVIEW, True
    End Sub

  4. #4
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    Macro of VBA to Export Report as PDF

    The path needs a filename need file extension.
    You will need it in quotes as it is a string.
    Code:
    DoCmd.OutputTo acOutputReport, "rptLTR1RefundRequest", acFormatPDF, "S:\Finance\Accounting\Overpayment-Collections\PENDING REVIEW\filename.pdf", True

  5. #5
    buck is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    26
    ok great that worked, can you also tell me how I can add the date to the filename when exporting please?

  6. #6
    AlexHedley's Avatar
    AlexHedley is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    England
    Posts
    180

    Macro of VBA to Export Report as PDF

    Code:
    Dim strPathAndFile As String
    strPathAndFile = "S:\Finance\Accounting\Overpayment-Collections\PENDING REVIEW"
    
    Dim fileDate As String
    fileDate = Replace(Date(), "/", "")'26/12/2013 => 26122013
    
    strPathAndFile = strPathAndFile & "\filename_" & fileDate & ".pdf"
    Replace "filename_" with whatever you want to call it.
    I've added "_" to separate the filename from the date.

    Then pass strPathAndFile in the correct argument.

  7. #7
    buck is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    26
    Alex, thanks, you've been a big help.

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

Similar Threads

  1. Export to Excel Macro
    By NISMOJim in forum Macros
    Replies: 8
    Last Post: 01-23-2014, 09:09 PM
  2. Replies: 3
    Last Post: 11-11-2013, 04:50 PM
  3. EXPORT to Excel via Macro
    By ruggierm1 in forum Import/Export Data
    Replies: 15
    Last Post: 09-25-2012, 09:33 AM
  4. Macro to export to excel
    By jlclark4 in forum Import/Export Data
    Replies: 5
    Last Post: 04-15-2011, 08:36 AM
  5. Replies: 0
    Last Post: 01-12-2011, 12:43 PM

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