Hi I have a report that will create multiple PDF per Agency and what I want only that Agency information on each page. I am getting everyone's information for every agency.
Here is my code:
Private Sub Label315_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsEmp As DAO.Recordset
Dim MyFileName As String
Dim strWhere As String
Dim mypath As String
Dim temp As String
mypath = "W:\Call Center\Call Center Reports\Agency_Reports\"
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT [Employer] FROM [Agency_Hours]", dbOpenDynaset)
'Clear previously built Agency Employer list - 210119 - SF
DoCmd.OpenQuery "qClrAgencyEmployer", acViewNormal, acEdit
'Build Agency Employer list for current run - 210119 - SF
DoCmd.OpenQuery "qAddAgencyEmployer", acViewNormal, acEdit
Set rsEmp = db.OpenRecordset("SELECT [Employer] FROM [AgencyEmployer]", dbOpenDynaset)
Do While Not rsEmp.EOF
temp = rsEmp("Employer")
'MyFileName = rs("Employer") & ".PDF" 'You can explore assigning the other field names
MyFileName = temp & ".PDF" 'You can explore assigning the other field names
strWhere = "[Employer] =" & temp
DoCmd.OpenReport "timecard_agency_daterange_TZ", acViewReport, strWhere
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "Agency Report to PDF"
rsEmp.MoveNext
Loop
Set rs = Nothing
Set db = Nothing
End Sub
Thank you
Here is my code:
Private Sub Label315_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim rsEmp As DAO.Recordset
Dim MyFileName As String
Dim strWhere As String
Dim mypath As String
Dim temp As String
mypath = "W:\Call Center\Call Center Reports\Agency_Reports\"
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT [Employer] FROM [Agency_Hours]", dbOpenDynaset)
'Clear previously built Agency Employer list - 210119 - SF
DoCmd.OpenQuery "qClrAgencyEmployer", acViewNormal, acEdit
'Build Agency Employer list for current run - 210119 - SF
DoCmd.OpenQuery "qAddAgencyEmployer", acViewNormal, acEdit
Set rsEmp = db.OpenRecordset("SELECT [Employer] FROM [AgencyEmployer]", dbOpenDynaset)
Do While Not rsEmp.EOF
temp = rsEmp("Employer")
'MyFileName = rs("Employer") & ".PDF" 'You can explore assigning the other field names
MyFileName = temp & ".PDF" 'You can explore assigning the other field names
strWhere = "[Employer] =" & temp
DoCmd.OpenReport "timecard_agency_daterange_TZ", acViewReport, strWhere
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
DoCmd.Close acReport, "Agency Report to PDF"
rsEmp.MoveNext
Loop
Set rs = Nothing
Set db = Nothing
End Sub
Thank you