docmd.close

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

Guest

I have a button on a form, what I want to do is when the button is pushed
close ALL open forms, reports, tables, EXCEPT one form (this one form opens
when you open the database and I want it to stay open the entire time).

Is it possible to do something like this with the docmd.close or a different
way.
 
Hi dustin15,

Yes, you can use docmd.close if you use the following syntax:

docmd.close acForm, FORMNAME

where FORMNAME is the name of the form that is open.

If you put it in a loop you could cycle through all forms and check if it's
open, closing it as above if it is.

Damian.
 
dustinl15 said:
I have a button on a form, what I want to do is when the button is pushed
close ALL open forms, reports, tables, EXCEPT one form (this one form opens
when you open the database and I want it to stay open the entire time).

Is it possible to do something like this with the docmd.close or a different
way.

You need to loop through the Forms collection backwards testing the name of each
form. If the name is the form you don't want to close then skip that one. The
indexes of the Forms collection change as you close forms. That is why you have
to loop backwards.

If as you say the one to not close is the first form opened at startup then it
should be at index zero, but I would still test the name property to be certain.
 
To answer your question as asked, yes, docmd can do the job but you'd
want to first test that the current form in the 'closeit loop" is not
the one you want kept open.

The way you asked your question causes me to wonder if you're looking
for a faux Autoclose macro. If you already have the code you want to
run placed in the close event of that form then you can simply put
Application.Quit in your command button. Since the form of interest
is the first one opened, in the absence of other direction, Access
will close open forms in inverse order of their opening. i.e. that
first opened form will be the last form closed.

HTH
 

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