Running a Report Multiple Times from a Form

  • Thread starter Thread starter FRKoron
  • Start date Start date
F

FRKoron

I have a form used to identify selection criteria for a
report. When the <Report> button is pushed, the report
opens with the selected criteria. No problem. I would
like to be able to run the report multiple times when the
<Report> button is pushed. I would like the next version
of the report to open after the user closes the first
version of the report. The problem arises in the Form
Module. It accurately runs multiple times and accurately
changes the criteria each time, but it only opens the
report once. It runs through the remaining code while the
first version of the report is open. How do I get it to
wait? Thanks.
 
FRKoron said:
I have a form used to identify selection criteria for a
report. When the <Report> button is pushed, the report
opens with the selected criteria. No problem. I would
like to be able to run the report multiple times when the
<Report> button is pushed. I would like the next version
of the report to open after the user closes the first
version of the report. The problem arises in the Form
Module. It accurately runs multiple times and accurately
changes the criteria each time, but it only opens the
report once. It runs through the remaining code while the
first version of the report is open. How do I get it to
wait? Thanks.

It seems to me you could use a loop with DoEvents to wait until the
report is no longer open. I'm assuming you're talking about opening the
report in print preview mode. Try something along these lines:

Dim strCriteria As String

strCriteria = <some criteria>

DoCmd.OpenReport "Report1", acViewPreview, _
WhereCondition:=strCriteria

While IsLoaded("Report1", acReport)
DoEvents
Wend

strCriteria = <some other criteria>

DoCmd.OpenReport "Report1", acViewPreview, _
WhereCondition:=strCriteria

While IsLoaded("Report1", acReport)
DoEvents
Wend

' ... and so on ...

The above code uses the following function, which is defined in a
standard module:

'---- start of function code -----
Function IsLoaded(ObjectName As String, _
Optional ObjectType As Integer = acForm) _
As Boolean

If SysCmd(acSysCmdGetObjectState, _
ObjectType, ObjectName) _
= acObjStateOpen
Then
Select Case ObjectType
Case acForm
If Forms(ObjectName).CurrentView <> 0 Then
IsLoaded = True
End If
Case Else
IsLoaded = True
End Select
End If

End Function
'---- end of function code -----
 
Back
Top