Solved

Save Access Report to PDF

Posted on 2013-11-25
6
872 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
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 34

Accepted Solution

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

Open in new window

0
 
LVL 47

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
    rs.MoveNext
Loop
Set rs = Nothing
docmd.close acReport, rpt.name
set rpt = nothing
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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 47

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.
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now