Opening form 2 from form 1 - what form/event to close form 1 
Author Message
 Opening form 2 from form 1 - what form/event to close form 1

When you are opening one form from another form, and want to close the
first form - where/when is the best time to close the first form?
Should the close command code be on the first form, following or before
the code opening the second form, or should it be on the open event of
the second form?  What if there is an error opening the second form or
closing the first form?

TIA -
--
Erin O'Leary
Energy & Environmental Research Center

Sent via Deja.com
http://www.*-*-*.com/



Mon, 16 Jun 2003 22:56:53 GMT  
 Opening form 2 from form 1 - what form/event to close form 1
I would put the close command in the form being opened if you are always
going to open that form from the first form.  If not include a test to see
if form one is open and if yes then close form one.

See SysCmd acSysCmdGetObjectState  in Help for more details
ObjectState = SysCmd(action[, objecttype][, objectname])

A better way to do this
If SysCmd(acSysCmdGetObjectState, acform, "Form1")>0 then DoCmd.Close
acForm,"Form1"

Alan

Quote:

> When you are opening one form from another form, and want to close the
> first form - where/when is the best time to close the first form?
> Should the close command code be on the first form, following or before
> the code opening the second form, or should it be on the open event of
> the second form?  What if there is an error opening the second form or
> closing the first form?

> TIA -
> --
> Erin O'Leary
> Energy & Environmental Research Center

> Sent via Deja.com
> http://www.deja.com/



Tue, 17 Jun 2003 01:00:03 GMT  
 Opening form 2 from form 1 - what form/event to close form 1
It depends...  If you want to refer to a value contained in the first form
you will have to keep it open. If you're not carring a value from the first
form to the second form it does not matter. Have something like this on the
button who will open your second form.

Docmd.close
Docmd.Open("YourSecondForm")

Matt LeBlanc


Quote:
> When you are opening one form from another form, and want to close the
> first form - where/when is the best time to close the first form?
> Should the close command code be on the first form, following or before
> the code opening the second form, or should it be on the open event of
> the second form?  What if there is an error opening the second form or
> closing the first form?

> TIA -
> --
> Erin O'Leary
> Energy & Environmental Research Center

> Sent via Deja.com
> http://www.deja.com/



Tue, 17 Jun 2003 01:11:51 GMT  
 Opening form 2 from form 1 - what form/event to close form 1
Matt -

The part I don't get is this, (even tho I know it works)...why does the
code run to open the second form when it is placed after the code to
close the first form?  You would think that when the close event starts
for the form, no more code after that point would run, except code in
the unload event.  I just don't have a very good understanding of
coding behind forms.

Erin O'Leary
Energy & Environmental Research Center



Quote:
> It depends...  If you want to refer to a value contained in the first
form
> you will have to keep it open. If you're not carring a value from the
first
> form to the second form it does not matter. Have something like this
on the
> button who will open your second form.

> Docmd.close
> Docmd.Open("YourSecondForm")

> Matt LeBlanc

--
Erin O'Leary
Energy & Environmental Research Center

Sent via Deja.com
http://www.deja.com/



Tue, 17 Jun 2003 06:25:15 GMT  
 Opening form 2 from form 1 - what form/event to close form 1
Erin,

Basically your code will execute to the end of the sub (unless half way you
write Exit Sub).  By writing Docmd.Close it will automatically close the
current form. It will still run the code to the end so if you tell Access to
open a second form it will regardless of the first Docmd.Close.  I know it's
not a very technical answer but it basically run that way.  Hope it helps...

Matt LeBlanc


Quote:
> Matt -

> The part I don't get is this, (even tho I know it works)...why does the
> code run to open the second form when it is placed after the code to
> close the first form?  You would think that when the close event starts
> for the form, no more code after that point would run, except code in
> the unload event.  I just don't have a very good understanding of
> coding behind forms.

> Erin O'Leary
> Energy & Environmental Research Center



> > It depends...  If you want to refer to a value contained in the first
> form
> > you will have to keep it open. If you're not carring a value from the
> first
> > form to the second form it does not matter. Have something like this
> on the
> > button who will open your second form.

> > Docmd.close
> > Docmd.Open("YourSecondForm")

> > Matt LeBlanc

> --
> Erin O'Leary
> Energy & Environmental Research Center

> Sent via Deja.com
> http://www.deja.com/



Wed, 18 Jun 2003 01:01:42 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Modal Form: Form Load, Form Open, Form Activate events do not Fire

2. Closing a form when other form is opening but reopening when all forms closed

3. Proper way to close a form in the Form Load event

4. Opening a table or form while other forms are open resizes all forms smaller

5. Close a form within its form event (not OnOpen)

6. Reopening a form from the forms on close event

7. small form opens medium form opens big form

8. Small form opens medium form opens big form

9. Close a form within its form event (not OnOpen)

10. Close a form within its form event (not OnOpen)


 
Powered by phpBB® Forum Software © phpBB Group