docmd.close

D

dimpie

Hi - I am trying to close all the forms before opening the main form.

With this command docmd.close, i can close only one form. I would like to
close all open forms and then open the main form. How can i do this??

here is what i presently have

docmd.close
docms.openform "Main form"


any help is appreciated.

Thanks
 
R

Rick Brandt

dimpie said:
Hi - I am trying to close all the forms before opening the main form.

With this command docmd.close, i can close only one form. I would
like to close all open forms and then open the main form. How can i
do this??

here is what i presently have

docmd.close
docms.openform "Main form"


any help is appreciated.

Thanks


Dim i as Integer
i = Forms.Count - 1

Do Until i < 0
DoCmd.Close acForm Forms(i).Name
i = i - 1
Loop

It is important that you loop through the collection from highest to lowest for
the value of i instead of lowest to highest. Otherwise you will close every
other form instead of all of them.
 
J

John W. Vinson

Hi - I am trying to close all the forms before opening the main form.

With this command docmd.close, i can close only one form. I would like to
close all open forms and then open the main form. How can i do this??

here is what i presently have

docmd.close
docms.openform "Main form"

The database's Forms collection consists of all *open* forms: to close them,
loop through them in descending order:

Dim iPos As Integer
Dim db As DAO.Database
Set db = CurrentDb
For iPos = db.Forms.Count - 1 to 0 Step -1
DoCmd.Close acForm, db.Forms(iPos).Name
Next iPos


John W. Vinson [MVP]
 

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

Top