Save Access Report to PDF

Posted on 2013-11-25
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 but the installer there contains ads; the sourceforge download does not.

LVL 37

Accepted Solution

PatHartman earned 500 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 (Access MVP)
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,
set rpt = nothing
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


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 (Access MVP)
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

707 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