Closing multiple forms 
Author Message
 Closing multiple forms

I  have a program which frequently switches from form to form using
'unload form1'
'form2.show'
This works properly, however, when I try to close a form (the application)
using the close 'x' button on the right hand corner of the title bar it
closes that form but does not close the application. How do I unload the
enire application??



Sun, 16 Jul 2000 03:00:00 GMT  
 Closing multiple forms

In the unload event of that form , use the END statement . A better idea is
to unload all the other forms of the app , and then use END .

Regards,
 Priya
 Trisoft Design
 E 30 Connaught Place
 New Delhi 110 001 - India
 Tel: 372 5407, 373 8651, 373 8653 Fax: 372 5407

 Internet:http://www.spindia.com/



Quote:
> I  have a program which frequently switches from form to form using
> 'unload form1'
> 'form2.show'
> This works properly, however, when I try to close a form (the
application)
> using the close 'x' button on the right hand corner of the title bar it
> closes that form but does not close the application. How do I unload the
> enire application??




Sun, 16 Jul 2000 03:00:00 GMT  
 Closing multiple forms

Hi Fred:

Quote:
>when I try to close a form (the application)
>using the close 'x' button on the right hand corner of the title bar it
>closes that form but does not close the application. How do I unload the
>enire application??

The proper way to close an application is to unload all loaded forms.  The
best place to do this is the Unload event of the main form of the
application, i.e.

Private Sub Form_Unload(Cancel As Integer)
  Dim Idx As Integer
  For Idx = Forms.Count - 1 To 0 Step -1
    Unload Forms(Idx)
  Next Idx
End Sub

Hope this helps,

Doug.



Sun, 16 Jul 2000 03:00:00 GMT  
 Closing multiple forms

The application will close when all forms have been unloaded.  If your
application does not close then a form must still be loaded but not
show.
I wrote simple program that does exactly what you said and it did close
when the X is pressed.

Try putting:

unload Form1
set Form1 = Nothing
form2.show

An "untidy" way to fix this, if all else fails, is to put End in the
QueryUnload event, i.e.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If UnloadMode <> vbFormCode Then
        End
    End If
End Sub

Remember though: end stops the program dead, without Unload and
Terminate events being fired.

If your still stuck ,send me the code, or a example that does what you
say.

Shane.

Quote:
> -----Original Message-----

> Posted At: 28 January 1998 18:30
> Posted To: winapi
> Conversation:      Closing multiple forms
> Subject:   Closing multiple forms

> I  have a program which frequently switches from form to form using
> 'unload form1'
> 'form2.show'
> This works properly, however, when I try to close a form (the
> application)
> using the close 'x' button on the right hand corner of the title bar
> it
> closes that form but does not close the application. How do I unload
> the
> enire application??




Mon, 17 Jul 2000 03:00:00 GMT  
 Closing multiple forms

I've read the other 3 posts.  Two of them are accurate and another is
totally wrong.  Never use the End statement.  What Shane said is accurate.
For some reason or another one of your forms are not being unloaded
properly.  This can be due to a number of reasons.  To help make sure each
form is unloaded also add the line:

    Set <form name> = Nothing

in each forms Unload event.  This will for all form level variable and
objects to be cleared and return that memory back to windows.

Also, what Doug said is correct.  But there are other ways w/o any coding.
First, if it is a mdi application the mdi form should be the main
application.  Then every child form will automatically be unloaded when the
mdi form is unloaded.  Of course this will only work w/o code if all the
forms are children forms.  You will need to incorporate Dougs suggestion
into your app.  Another way is strictly only if you are using VB5.  The show
method has another parameter, ownerform (i.e. form.show <state>,
<ownerform>).  If your app is a non mdi app then you can mimick the mdi
form/child form behavior by using a form name in the ownerform parameter.
That way, when you mimimize or restore that form (used in the parameter),
any forms shown with that as the owner form will mimimize/restore also.  The
same goes for unloading.  If you unload the ownerform, the other forms will
unload.

After all this though, one thing still stands, put the Set <form> = Nothing
in all form/mdi form Unload events.

Now, if this doesn't cure the problem, make sure you are not referencing any
controls or variables of another form after unloading it.  This happens
sometimes.

Tony Fountain
Digital Horizons, Inc.
Senior Application Developer


remove NOSPAM. to respond directly.

Quote:

>I  have a program which frequently switches from form to form using
>'unload form1'
>'form2.show'
>This works properly, however, when I try to close a form (the application)
>using the close 'x' button on the right hand corner of the title bar it
>closes that form but does not close the application. How do I unload the
>enire application??




Mon, 17 Jul 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Closing Multiple Forms on Exit

2. Opening and closing multiple forms - How?

3. Forms, primary thread closing when closing startup form

4. Form Close Button Does Not Close the Form

5. Open form, close form, open form = disposed object exception

6. Prevent user from closing form using caption close button

7. Closing a form and closing Word

8. Tip : VB.NET Form Won't Close on Me.Close + User Controls

9. Form does not close from the UpperRight X Close button

10. Do I Find or Write the new Form Events (Activated,DeActivated,Closing,Closed)

11. problems using close [x] button when closing forms.

12. window.close closes webbrowser but not the form itself

 

 
Powered by phpBB® Forum Software