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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,089
Messages
6,123,058
Members
449,091
Latest member
ikke

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