1 Report Multiple PDF's

mborg

New Member
Joined
Nov 22, 2010
Messages
43
Need to make report books and save each as a pdf. Each book is dependent on a certain Field (ID). Where the ID is the same, need to have a book. There are about 5000 pages of data, and should be about 150 books. Instead of going into a query 150 times, changing the criteria and rerunning the report I want to be able to just run a vba script that loops through and saves off a book of the report... Here is what I have so far. Please advise. I am getting a compile error, plus I am not even sure if the code is proper:


Private Sub Report_Open(Cancel As Integer)

Dim sql As String
Dim db As Database
Dim rs As Recordset
sql = "SELECT [Distribution] FROM [qry1]"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Do Until rs.EOF
DoCmd.OpenReport "Report", acViewPreview,,"ID = " &
rs!ID
DoCmd.OutputTo
acOutputReport , "Report", [acFormatPDF], "C:\" & ID & ".pdf"
DoCmd.Close acReport, "Report"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Need to make report books and save each as a pdf. Each book is dependent on a certain Field (ID). Where the ID is the same, need to have a book. There are about 5000 pages of data, and should be about 150 books. Instead of going into a query 150 times, changing the criteria and rerunning the report I want to be able to just run a vba script that loops through and saves off a book of the report... Here is what I have so far. Please advise. I am getting a compile error, plus I am not even sure if the code is proper:


Private Sub Report_Open(Cancel As Integer)

Dim sql As String
Dim db As Database
Dim rs As Recordset
sql = "SELECT [Distribution] FROM [qry1]"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql, dbOpenSnapshot)
Do Until rs.EOF
DoCmd.OpenReport "Report", acViewPreview,,"ID = " &
rs!ID
DoCmd.OutputTo
acOutputReport , "Report", [acFormatPDF], "C:\" & ID & ".pdf"
DoCmd.Close acReport, "Report"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub



I assume you are sing Access 2007 or 2010. Is that correct?

First you need to put the coen in a differnt event thatn a report's On Open event,( Report_Open)

I would recommend using the On Click event of a Command Button.

I have created an example for Access 2007/2010 that shows I how I like to handle this. See: Batch Printing and Save As PDF
 
Upvote 0

Forum statistics

Threads
1,215,129
Messages
6,123,210
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top