Report filter not changing when sub routine runs

Attached is the module I am running to loop through a report to run selective reports based on a query.  The report has a group equal to the Sueprvisor in the main query.  The controlling query has 10 records with just the Supervisor, a character field.

When I step through the module, the report outputs to the separate pdf files as I expected.  However, when I run the module, the data is only for the last Supervisor processed.  The file name changes as expected, but not the data.

I would appreciate any help in correcting this.

Thanks

glen
Public Sub Supervisor()
    Dim MyRs As DAO.Recordset
    Dim rpt As Report
   
    Set MyRs = CurrentDb.OpenRecordset("qry_Active_Employee_Supv")
    DoCmd.OpenReport "rpt_Active_Employees_By_Department", acPreview, , , acHidden
    Set rpt = Reports("rpt_Active_Employees_By_Department")
   
    With MyRs
        .MoveFirst
            Do While Not .EOF
                ' open report hideen and filtered
                ' save the hidden report as a PDF
                 rpt.Filter = "[Supervisor] = " & Chr(34) & !Supervisor & Chr(34)
                 rpt.FilterOn = True
                DoCmd.OutputTo acOutputReport, "rpt_Active_Employees_By_Department", acFormatPDF, "\\pmcfs\groups\HR\HR Extractions\ActiveEmployees\Active_Empl_List_" & !Supervisor & ".PDF"
    
               .MoveNext
            Loop
    End With
    rpt.Filter = " "
    rpt.FilterOn = False
End Sub

Open in new window

GPSPOWAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SimonCommented:
You could try adding these line to ensure the filter is applied each time and that the PDF generator has time to execute for each loop...
                ' save the hidden report as a PDF
                 rpt.FilterOn = False
                 rpt.Filter = "[Supervisor] = " & Chr(34) & !Supervisor & Chr(34)
                 rpt.FilterOn = True
                DoCmd.OutputTo acOutputReport, "rpt_Active_Employees_By_Department", acFormatPDF, "\\pmcfs\groups\HR\HR Extractions\ActiveEmployees\Active_Empl_List_" & !Supervisor & ".PDF"
                 DoEvents
0
SimonCommented:
I also use a KillTime function like this if I need to pause a routine to allow for other things to execute
Function KillTime(t As Single)
Dim sTime As Single, ctr As Long
sTime = Timer
Do Until Timer > sTime + t
DoEvents
ctr = ctr + 1
Loop
KillTime = ctr
End Function

Open in new window


You can use this in place of the DoEvents line if necessary
e.g. KillTime(0.5) or KillTime(2) to yield to the operating system for 1/2 or 2 seconds respectively.
0
GPSPOWAuthor Commented:
SELECT qry_Active_Employees_By_Department.Supv AS Supervisor
FROM qry_Active_Employees_By_Department
GROUP BY qry_Active_Employees_By_Department.Supv;

Open in new window


SELECT qry_Active_Employees_By_Department.Supv AS Supervisor, qry_Active_Employees_By_Department.DeptID, qry_Active_Employees_By_Department.DeptName, qry_Active_Employees_By_Department.JobCodeID, qry_Active_Employees_By_Department.PositName, qry_Active_Employees_By_Department.LastName, qry_Active_Employees_By_Department.FirstName, qry_Active_Employees_By_Department.EmployeeID, qry_Active_Employees_By_Department.EmpType, qry_Active_Employees_By_Department.BaseRate, qry_Active_Employees_By_Department.DOB
FROM qry_Active_Employees_By_Department
ORDER BY qry_Active_Employees_By_Department.Supv, qry_Active_Employees_By_Department.DeptID, qry_Active_Employees_By_Department.JobCodeID, qry_Active_Employees_By_Department.LastName;

Open in new window


Public Sub Supervisor()
    Dim MyRs As DAO.Recordset
    Dim rpt As Report
   
    Set MyRs = CurrentDb.OpenRecordset("qry_Active_Employee_Supv")
    DoCmd.OpenReport "rpt_Active_Employees_By_Department", acPreview, , , acHidden
    Set rpt = Reports("rpt_Active_Employees_By_Department")
   
    With MyRs
        .MoveFirst
            Do While Not .EOF
                ' open report hideen and filtered
                ' save the hidden report as a PDF
                 rpt.FilterOn = False
                 rpt.Filter = "[Supervisor] = " & Chr(34) & !Supervisor & Chr(34)
                 rpt.FilterOn = True
                DoCmd.OutputTo acOutputReport, "rpt_Active_Employees_By_Department", acFormatPDF, "\\pmcfs\groups\HR\HR Extractions\ActiveEmployees\Active_Empl_List_" & !Supervisor & ".PDF"
                DoEvents
               .MoveNext
            Loop
    End With
    
End Sub

Open in new window


I tried using the Rpt.filter=False & DoEvents but they had no effect on the output.  The Report ran with all 24 supervisors getting the same report.

The First code snippet is the Query to create the RecordSet.
the Second code snippet is the Query used by the report.
The Third code snippet is the module used to generate the report pdf's.

Would it be better to insert a strSql string within the module to create a report output query with a Where clause to designate the Supervisor value to print as it loops through the Supervisor query?

Thanks

Glen
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

SimonCommented:
Hi Glen, I possibly misundertood your problem. I thought you meant it worked as intended when you stepped through it as opposed to letting it run at full speed.
0
GPSPOWAuthor Commented:
It did.

Is my syntax correct where I use Rpt.FilterOn=False and the  DoEvents?

There are a total of 58 pages in the report when I run it without a Supervisor filter.  For each output, the name changes for the file name but the data stays the same.

Thanks

Glen
0
SimonCommented:
This works. Open and close the report within the loop, using a where clause instead of a filter:
Public Sub Superevisor()
    Dim MyRs As DAO.Recordset
    Dim rpt As Report
   
    Set MyRs = CurrentDb.OpenRecordset("qry_Active_Employee_Supv")
       
    With MyRs
        .MoveFirst
            Do While Not .EOF
                'Open report with where clause to limit to single supervisor and hidden
                DoCmd.OpenReport "rpt_Active_Employees_By_Department", acPreview, , "[Supervisor] = " & Chr(34) & !Supervisor & Chr(34), acHidden
                Set rpt = Reports("rpt_Active_Employees_By_Department")
                DoCmd.OutputTo acOutputReport, rpt.Name, acFormatPDF, "\\pmcfs\groups\HR\HR Extractions\ActiveEmployees\Active_Empl_List_" & !Supervisor & ".PDF"
                DoCmd.Close acReport, rpt.Name
               .MoveNext
            Loop
    End With
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GPSPOWAuthor Commented:
Perfect!!

Thank you very much.

Glen
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.