Closing a form

J

Jerry Anderson

I have a form that opens another form based on a selection from a list box.
Loading the new form is triggered by the AfterUpdate event. After the new
form opens, what is the code to close the original?
 
D

Dirk Goldgar

Jerry Anderson said:
I have a form that opens another form based on a selection from a list box.
Loading the new form is triggered by the AfterUpdate event. After the new
form opens, what is the code to close the original?


The code that opens the new form can also close the current form:

DoCmd.OpenForm, "frmNewForm"
DoCmd.Close acForm, Me.Name, acSaveNo

The above code uses the current form's Name property to supply the name of
the form to be closed. If you want to close some other form, say "FormB",
you could write:

DoCmd.Close acForm, "FormB", acSaveNo

The acSaveNo argument instructs Access not to save any design changes to the
form. Note that it has nothing to do with saving any modified *data* on the
form -- that will happen automatically when you close the form, so long as
there's nothing (data validation errors, for example) to prevent it.
 
J

Jerry Anderson

Dirk Goldgar said:
The code that opens the new form can also close the current form:

DoCmd.OpenForm, "frmNewForm"
DoCmd.Close acForm, Me.Name, acSaveNo

The above code uses the current form's Name property to supply the name of
the form to be closed. If you want to close some other form, say "FormB",
you could write:

DoCmd.Close acForm, "FormB", acSaveNo

The acSaveNo argument instructs Access not to save any design changes to the
form. Note that it has nothing to do with saving any modified *data* on the
form -- that will happen automatically when you close the form, so long as
there's nothing (data validation errors, for example) to prevent it.


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

Works like a champ! Thanks!
 
Top