?
Solved

Save Access Report to PDF

Posted on 2013-11-25
6
Medium Priority
?
911 Views
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..."
0
Comment
Question by:bhlabelle
[X]
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
6 Comments
 
LVL 35

Expert Comment

by:mvidas
ID: 39675556
Hi,

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.
http://sourceforge.net/projects/pdfsam/
There are more program details at http://www.pdfsam.org/ but the installer there contains ads; the sourceforge download does not.

Matt
0
 
LVL 38

Accepted Solution

by:
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
    rs.MoveNext
Loop
Set rs = Nothing

Open in new window

0
 
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
    rs.MoveNext
Loop
Set rs = Nothing
docmd.close acReport, rpt.name
set rpt = nothing
0
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!

 

Author Comment

by:bhlabelle
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.?
0
 
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.
0
 

Author Comment

by:bhlabelle
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.
0

Featured Post

Industry Leaders: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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