[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

Save Access Report to PDF

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
bhlabelle
Asked:
bhlabelle
1 Solution
 
mvidasCommented:
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
 
PatHartmanCommented:
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
 
Dale FyeCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
bhlabelleAuthor Commented:
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
 
Dale FyeCommented:
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
 
bhlabelleAuthor Commented:
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now