IsLoaded help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have two forms frmStats and frmMoreStats that load and the user can toggle
between the two forms for data entry. Each form has a command button that
closes that form. The user starts with frmStats and enters data. The user may
or may not use frmMoreStats depending on their needs. What I need to do is
when the user clicks on the exit button on frmStats, a check to see if the
other form is loaded and if so, close both forms. I would appreciate any
help, thank you.
 
Hi,

I needed to do the same with reports. The following is a copy of my post in
the reports NG using an altered solution found on mvps.org, what you need to
use is the public function and changing acReport to acForm. Check the value
the function returns when passed the form name that you need to check on. I
have done that in the OnClose event of my code checking for open reports.
Have a look at mvps.org for the original forms solution as my line "If
Reports(strObjectName).Pages <> Then"
differs from the original slightly.

Regards.

Terry said:
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

*** Solution ***

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



?
 
If you use A2K or later, add in your code for the cmdExit_Click Event:

****Untested****
If CurrentProject.AllForms("frmMoreStats").IsLoaded Then
DoCmd.Close acForm, "frmMoreStats"
End If
********

You can also use the (frmStats) Form_Unload Event to do the above.
 
Back
Top