Close active form

J

Jason

Is it possible to create code that I can assign to command button on my
various forms that closes the form the button is on and then opens my
"mainform"? I am trying to avoid having to write a macro for every single
form in my application.
 
M

mscertified

Normally when a form opens another form, both stay open and when you close
the second form the previous form reappears.

-Dorian
 
D

Dale Fye

But in some instances, you might close or hide the previous form.

To close the current form, use:

docmd.close acform, me.name

Follow that up with:

If application.allforms("mainform").isloaded then
forms("mainform").visible = true
forms("mainform").setfocus
else
docmd.openform "mainform"
endif

Put all that code in the click event of a command button.

HTH
Dale
 

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