Microsoft Access 2007 Export Report for each record within a recordset
I am attempting to click a button on a form that will export a report that is unique to each record. I created a query that contains the Employer ID numbers that the report should be run for. I am unable to make it work. The report currently runs fine when I enter in the EmployerID number one at a time.
Below are the fields being used:
(BEEmployers) Qry with records that need reports run
(EmployerID) Column within query that contains record ID data that needs passed to report
(Annual) Name of report that needs printed for each record
I am attempting to click a button on a form that will export a report that is unique to each record. I created a query that contains the Employer ID numbers that the report should be run for. I am unable to make it work. The report currently runs fine when I enter in the EmployerID number one at a time.
Below are the fields being used:
(BEEmployers) Qry with records that need reports run
(EmployerID) Column within query that contains record ID data that needs passed to report
(Annual) Name of report that needs printed for each record
Code:
Private Sub AnnRptExportAll_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim ID As integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("BEEmployers")
If rs.RecordCount = 0 Then Exit Sub
rs.MoveFirst
Do Until rs.EOF
ID = rs![EmployerID]
DoCmd.OpenReport StDocName, acPreview, , "[employerid]=" & ID
DoCmd.OutputTo acReport, "Annual", acFormatPDF, "G:\Research\EFR_Export\NONBE\ER_" & ID & ".pdf"
DoCmd.Close
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
MsgBox ("Completed")
End Function
Comment