Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to close multiple forms? 2

Status
Not open for further replies.

bigchuck

Programmer
Oct 10, 2002
14
US
Is there a way to close every open form and then open another form (like a main menu)?
 
There is a IsOpen function in the Solutions Database (I think), and you could cycle through all the forms to see if they are open, and if they are to close them. And then you could open a new form.

Is that what you are looking for.
I'm not sure that there is a command to close all open forms? Although you could easily build a method to do that with the above as well as using the system references to all the forms in the database. There was a sample database called explorer (I think that's the name) that demonstrated this point.

David Pimental
(US, Oh)
dpimental@checkfree.com
 
Hi bigchuck,

This looks like a bit of fun! If you run this little code loop it gives you the names of all the open forms.

Code:
Dim frm As Form
For Each frm In Forms
    MsgBox frm.Name
Next

You might now be tempted to think that this snippet would, therefore, close them. But don't be fooled!

Code:
Dim frm As Form
For Each frm In Forms
    DoCmd.Close acForm, frm.Name
Next

What I think is the problem is that after closing the first Form it looks for the second Form and finds what used to be the third form, etc. This seems a pretty poor way of running through a collection but, nonetheless, we have to fall back on procesing from the end backwards to avoid the trap. Even this is not simple because the forms collection is zero-based, but what we get is:

Code:
Dim f As Integer
For f = Forms.Count - 1 To 0 Step -1
    DoCmd.Close acForm, Forms(f).Name
Next

After closing all the open forms, you can now open your new one, or do anything else you want.

Code:
DoCmd.OpenForm “
Code:
FormName
Code:

Enjoy,
Tony
 
Good work TonyJollans.

I was trying to get at that. Well done.

David Pimental
(US, Oh)
dpimental@checkfree.com
 
Well done, TonyJollans! A star is a pittance compared to the jam from which you have freed me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top