Test to see if a form is open

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

Guest

I have a form that needs another form to be open for it to work. What I want
to do though is when the user closes one of the forms both close.

I have it working with one of the forms, but the user must close that form
first. If I add the same to the other form I get an error as it tries to
close a form that has already been closed. What I want is a way to check
whether the other form is open or not.

Can anybody help?
 
In Access 2000 and later, you can use:
If CurrentProject.AllForms("Form1").IsLoaded Then

In all versions, you can use:
If SysCmd(acSysCmdGetObjectState, acForm, "Form1") <> 0 Then
 
Well the test seems to work fine, but infortunatly if I close Form1 it
instructs Form2 to close as well.
Form2 has the same test as Form1 so if Form1 is open close it. Unfortunatly
by the time the test is run Form1 hasn't had time to close so it is reported
as being open the test comes back as true calusing the command to close Form1
to be run and thus creating an error.
 
There will normally be a dependency here, e.g. Form1 is the main one, and
Form2 is the helper. Therefore in the Close event of Form1, you include:
If CurrentProject.AllForms("Form2").IsLoaded Then
DoCmd.Close acForm, "Form2"
End If

Now if Form2 is open, it closes when Form1 does.
If it's not open Form1 closes okay.
If Form2 is a helper for Form1, you can close Form2 and leave Form1 open.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top