Link to home
Start Free TrialLog in
Avatar of ste_89
ste_89

asked on

Closing and Opening Multiple Forms in VB6

Hi,

I wish to open mutiple copies of the same form in VB6 whenever a user clicks on a menu item with something like the following:


Private Sub mnuOpenNewForm_Click()
     Dim NewForm As frmNewForm
     Set NewForm = New frmNewForm
     NewForm.Show
End Sub

This works fine and open a new instance of Newform every time the menu option is clicked, however when I try to close the project it remains in memory and doesn't terminate the application.

Is there something I am doing wrong? Do I have to set the NewForm object to nothing when the form closes?

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ste_89
ste_89

ASKER

Is form.close VBA and not VB6?

Tried this and it appeared to work ok:

Private Sub Form_Unload(Cancel As Integer)
For Each Form In Forms
   Unload (Form)
   Next Form
End Sub
how do you close the project? you can use the End statement
forexample if the forms are child forms of an MDI form then you can try something like:

MDIForm1_Unload(Cancel As Integer)
      End
End Sub

regards
Pi7
Pi7 >> while using the End statement to terminate the program will in fact work, it is precisely comparable to stopping your car by smashing it into a BRICK WALL, when a judicious application of the brakes would be just as effective, and MUCH safer for the occupants of the car.

The End statement will STOP everything, IMMEDIATELY, and if there are valuable resources (such as Database connections or file Handles) that are still in use, they will be trashed, and may cause more serous problems later on.  Using the End statement is generally a VERY VERY VERY (get the idea) bad habit to get into.

AW
Avatar of ste_89

ASKER

Thanks for your replies. I have used Dhaest's answer and avoided crashing my program into a brick wall.