Check for Open Reports

  • Thread starter Thread starter Terry
  • Start date Start date
T

Terry

I am opening upto three reports based on criteria in a form control. The
form is popup, modal, dialogue. When the user clicks a command button to
open the reports the forms visible property is set to false to hide the
form, this allows the report queries to get data from a form control.

What I need to do is keep the form open until the last report is closed and
then close the form on report close.

Assuming that any one of the reports may be the last, how would I check that
it is the last report left open?

Regards
 
Terry,

Application.Reports.Count

will give you the number of open reports at any time.

HTH,
Nikos
 
With thanks to mvps.org, http://www.mvps.org/access/forms/frm0002.htm I
resolved this, this way:

Placed this function in a general module:

Public Function rIsLoaded(ByVal strObjectName As String) As Integer
'Returns a 0 if form is not open or a -1 if Open

If SysCmd(acSysCmdGetObjectState, acReport, strObjectName) <> 0 Then
If Reports(strObjectName).Pages <> 0 Then
rIsLoaded = False
Else
rIsLoaded = True
End If
Else
rIsLoaded = True
End If

End Function

And this in the OnClose event of each report, commenting out the line that
has the name of the report in whos OnClose event the code resides. In this
case the report name is rpt_INV_Scheduled_Invoicing_AftYrAll, so the line
that has that name is commented out, no point in checking if itself is open:


Private Sub Report_Close()
Dim booCanClose As Boolean
booCanClose = rIsLoaded("rpt_INV_Scheduled_Invoicing_CurYrAll")
If booCanClose = False Then Exit Sub
booCanClose = rIsLoaded("rpt_INV_Scheduled_Invoicing_NxtYrAll")
If booCanClose = False Then Exit Sub
'booCanClose = rIsLoaded("rpt_INV_Scheduled_Invoicing_AftYrAll")
booCanClose = rIsLoaded("rpt_INV_Scheduled_Invoicing_CurYrClient")
If booCanClose = False Then Exit Sub
booCanClose = rIsLoaded("rpt_INV_Scheduled_Invoicing_AftYrClient")
If booCanClose = False Then Exit Sub
booCanClose = rIsLoaded("rpt_INV_Scheduled_Invoicing_NxtYrClient")
If booCanClose = False Then Exit Sub
If booCanClose = True Then
' close form
DoCmd.Close acForm, "frm_INV_Scheduled_Invoicing_Reports"
Else
' don't close form
End If

End Sub
 
Back
Top