Microsoft Access - Print separate pdf reports by groups using a command button.

Asked By Desiree on 28-Jun-12 11:03 AM
Earn up to 10 extra points for answering this tough question.
I have a report that is using grouping called Districts.  The number of Districts may vary every day.  I'd like to use a command button to print each report to a separate pdf based on group.  I have a separate select query to use as a filter, but I'm not sure how to write the code to loop through each District to create a pdf.

Thank you for your time
RAJASEKHAR RAJENDRAN replied to Desiree on 29-Jun-12 06:48 AM

Check the below link, which might solve your issue. 

also check the link which might help..

Thanks & Regards,
Pat Hartman replied to Desiree on 25-Jul-12 03:50 PM

The following is a code sample that reads a recordset based on a query and creates a separate PDF for each District.  OutputTo does not give you the option of a filter or Where clause as the OpenReport and OpenForm methods do so you have to do something else to get the report to run for one district at a time.  The easiest thing is for the report's RecordSource, use a query that references the form field you are filling with the current district.  If you want to also run this report using some other method, you'll need a bit of code in the report's Load event to decide which querydef to use as the RecordSource.

Dim db as DAO.Database
Dim qd as DAO.Querydef
Dim rs as DAO.Recordset
Dim strPath as String
Dim strDocName as String
Set db = CurrentDB()
Set qd = db.Querydefs!yourqueryname
Set rs = qd.OpenRecordSet
strPath = "C:\exportfolder\"
Do Until rs.EOF = True
  Forms!yourformname!yourcontrolname = rs!District
  strDocName = strpath & "SomeReportName_" & rs!District & ".pdf"
  Kill DocName    'delete existing file if any so outputto won't hang
  DoCmd.OutputTo acOutputReport, "somereportname", acFormatPDF, strDocName

asava samuel replied to Desiree on 09-Mar-13 06:23 AM
Here is an ORM that works with Microsoft Access