[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


Save Access Report to PDF

Posted on 2013-11-25
Medium Priority
Last Modified: 2013-11-25
I have a report in Access that will create a bunch of letters based on a date range.  There are usually 15-20 letters each time, but it is really one batch report.  Is there a way to save each letter as a separate pdf in vba?  I have seen where the entire 15-20 page report can be saved as one pdf, but my users are picky..."then we have to extract each letter one at a time..."
Question by:bhlabelle
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 35

Expert Comment

ID: 39675556

I don't have a direct answer to your question, short of iterating through the pages in the macro and first only printing page 1 to pdf, then printing only page 2 to pdf, etc.

A good alternative would be to use a separate splitting program, like PDFSAM (PDF Split and Merge). I use it frequently to split large PDF files, it is free and open source and very useful.
There are more program details at http://www.pdfsam.org/ but the installer there contains ads; the sourceforge download does not.

LVL 39

Accepted Solution

PatHartman earned 2000 total points
ID: 39675572
This is air code (no variables declared, untested) but it should give you the idea.  You have a control on a form that will hold the ID field.  Each time through the loop, you put in a new value so when you open the report, the report's RecordSource query can read the value and filter the report.
Set rs = qd.OpenRecordset
Do until rs.EOF
    Forms!yourform!yourID = rs!SomeID
    strFileName = strPath & "yourreport-" & rs!SomeID & "-" & Format(Date(), "yyyymmdd") & ".pdf" 
    DoCmd.OutputTo acOutputReport, "yourreport", acFormatPDF, strFileName
Set rs = Nothing

Open in new window

LVL 48

Expert Comment

by:Dale Fye
ID: 39675678
To take PatHartman's code just one step further.  I generally open the report first, so you only have to open it once.  Then I loop through the records in the recordset.  Opening and closing the report can take a significant amount of time, so you can save some by only opening it once, and then applying a filter to the opened report before using the OutputTo method.

The following is also air code!

docmd.openreport "yourReport", acViewPreview
set rpt = Reports("yourReport")
set rs = currentdb.openrecordset(rpt.recordsource)
Do until rs.EOF
    rpt.Filter = "[ID] = " & rs!ID
    strFileName = strPath & "yourreport-" & rs!SomeID & "-" & Format(Date(), "yyyymmdd") & ".pdf"
    DoCmd.OutputTo acOutputReport, "yourreport", acFormatPDF, strFileName
Set rs = Nothing
docmd.close acReport, rpt.name
set rpt = nothing
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.


Author Comment

ID: 39675722
PatHartman, I get a "Run-time error '2501', The OutputTo action was cancelled.

I know the report is working because I tried:
           DoCmd.OpenReport "Letters", acPreview
and the report opened correctly.  Just can't figure out why the OutputTo  is not working.  

I changed my default printer to Adobepdf, but this didn't help.

Also, I'm testing this by saving it out to my C:\ drive, so I know it exists. (well, unless you're really into philosophy...then one could argue about existence, but one thing at a time)

Any suggestions.?
LVL 48

Expert Comment

by:Dale Fye
ID: 39675810
what version of Access are you running?

When you open the report and right click on it, does the popup menu provide you with a way to export to PDF?  In 2003 you have do download the SaveAsPDF add-in, but the PDF format is native in 2007.

Author Comment

ID: 39675823
Ok, so I'm an idiot.  I guess I do not have permission to save to my C: drive.

PartHartman, your suggestion worked when I saved it to out network drive.

Also, thanks fyed, but I slightly changed how the process works.  No longer do we produce the letters in batch.  Once the record is entered, the letter is produced at that time, so no need to look through records.  Thanks for your input though.

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question