Question : How do I save one record per report in Access 2007

i am trying to save a series of reports where a report is saved for each record.  I currently have the report saving proplerly with a unique name per location identified in the query, however, when I open the reports, every one is the exact same, the first record.  For instance, I have location 1, location 2, and location 3.  the reports save with file names "location 1", "location 2", and "location 3", but every one is 3 pages with all locations ( I have them separated by a page break).  Below is the code:

Dim ReportName, Name1, DateNow, ExportName, ExportLoc, Site As String

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("FedbySiteQry")
Site = rs("Vault Name")
DateNow = Format(Now(), "MMM-DD-YYYY") 'CalStart
ReportName = "FedbySiteRpt"
ExportLoc = "c:/TEMP"

rs.MoveFirst
Do Until rs.EOF
 
ExportName = rs("Vault Name")

DoCmd.OutputTo acOutputReport, ReportName, "PDFFormat(*.pdf)", ExportLoc & "/" + ExportName & "_" & DateNow & ".pdf", False, "", 0, acExportQualityPrint

rs.MoveNext
Loop

How can I save each location to that specific file?

Thank you.

Answer : How do I save one record per report in Access 2007

As you have established, you cannot apply a filter in OutputTo.

So in this case you have to apply the filter in the report;  this requires 3  bits of code.

In a standard module declare a public variable :

Public myFilter as string

In the Report_open event procedure apply the filter..

IF Len(myfilter) > 0 then
   me.filter = myFilter
   me.filterOn = True
endif

In your current code you set up the filter:

ExportName = rs("Vault Name")

myFilter = "Locationfieldnamehere = '" & exportname & "'"      ' add this line with your own field name

DoCmd.OutputTo acOutputReport, ReportN.......




Random Solutions  
 
programming4us programming4us