Close all forms, then closing MDI Parent Help

G

Guest

Hi,
I have a form (switchboard like form) thats loaded into a MDI parent form.
This form is the start off point for all the other screens in the app. I have
placed a exit button on the switchboard and would like to use it to close all
app down. What is the best way to do that? I have the following code but it
won't close the MDI parent form.
for each frm as Form in MdiParent.MdiChildren
frm.Close
Next
MdiParent.Close >> Errors on this line
I get the following error:
An unhandled exception of type 'System.NullReferenceException' occurred in
NF.exe
Additional information: Object reference not set to an instance of an object.

Now, it don't have a problem through the loop, but errors on the last line.
What variable name should I be using for the default startup form (in my case
the MDI Parent).
In the Upgrade Support region, there is a reference named
m_vb6FormDefInstance, but this variable won't work sith the for each loop, so
I'm stuck alittle. By the way, the way the code above is written, it does
close the child forms that are open, its just getting the parent to close.
Thanks for any advice.
Michael
 
G

Guest

Hi Everyone,
I do have one solution that I tested and it seems to work, but I don't this
this is the best solution. What I did was create a form variable that I set
to a reference of the parent MDI form like so:
Code placed in the MDI parent load event
tempParentForm = me

Then in the exit button of the switchboard form I have the following code:
for each frm as Form in MdiParent.MdiChildren
frm.Close
Next
tempParentForm.Close

Is there a cleaner way to do this. Thanks for any advice.
Michael
 
A

Armin Zingler

Michael said:
Hi Everyone,
I do have one solution that I tested and it seems to work, but I
don't this this is the best solution. What I did was create a form
variable that I set to a reference of the parent MDI form like so:
Code placed in the MDI parent load event
tempParentForm = me

Then in the exit button of the switchboard form I have the following
code: for each frm as Form in MdiParent.MdiChildren
frm.Close
Next
tempParentForm.Close

Is there a cleaner way to do this. Thanks for any advice.
Michael

Why not only call Mdiparent.close?


Armin
 

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