It is essentially the same report ran 60 times using different criteria. We
incorporated two text boxes onto the form to display data depending on what
was selected in the combo box.
Here is a little more of the nuts and bolts:
A button executes the function below. The button is not on the form with the
combo box.
Here is the code that automates the report execution and saving:
-----------------------------------------------------------------------------------
On Error GoTo EOQ_Test3_Err
Dim location As String
Dim rsSVP As New ADODB.Recordset
Dim SVP As String
Dim conn As New ADODB.Connection
'*** CONNECT TO DATABASE ***
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=X:\XXX"
'Open the query and get the SVPs
rsSVP.Open "SELECT * FROM qrySVPList", conn, adOpenDynamic '***This
returns 60 users****
If rsSVP.EOF Then
MsgBox rsSVP.RecordCount
MsgBox "No SVPs Selected"
Else
while rsSVP.EOF = False
DoCmd.OpenForm "frmReports", acNormal
Forms!frmReports!cmboApprover = rsSVP.Fields("Approver")
Forms!frmReports!txtFirstName =
Forms!frmReports!cmboApprover.Column(1)
Forms!frmReports!txtLastName =
Forms!frmReports!cmboApprover.Column(0)
location = "X:\XXX" & Forms!frmReports!txtLastName & " " &
Forms!frmReports!txtFirstName & ".snp"
DoCmd.OutputTo acOutputReport, "rpt_Approver_Summary",
acFormatSNP, location, False
DoCmd.Close acForm, "frmReports"
rsSVP.MoveNext
Wend
End If
EOQ_Test3_Exit:
Exit Function
EOQ_Test3_Err:
MsgBox Error$
Resume EOQ_Test3_Exit
End Function
-----------------------------------------------------------------------------------------------
When we put a where clause to limit the rsSVp recordset, the reports that
had issues come back correct. The weird part is when we run the macro without
a where clause, the reports come back with missing records no matter where in
the recordset they occur (ie: the first report to come back has missing
records in it).
Again, the report is made up of main section and a subreport both executed
by different queries. The queries of both reports pass the first name and
last name parameters from the form. The missing records are NOT occuring in
the main report but in the subreport.
The report is successful whenever we limit the recordset in the code or run
it manually from the form.