Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unload all forms upon closing MDI form

Status
Not open for further replies.

ahhuang

Programmer
Apr 1, 2002
61
0
0
SG
i have a MDI form and some individual forms(not child).
how do i code in the way that when i click to close/unload MDI form, all other opened forms all also closed.
Thank you
 
In the form_unload event of the MDI form, loop through all of you open forms and close them.
 
Also do not use End in your code to exit the application, this will close down with out going through your unload routine.
 
'Add following code to the MDIForm_Unload event
'This code unloads all forms in "Forms" collection of VB.

Private Sub MDIForm_Unload(Cancel As Integer)
Dim frm As Form

For Each frm In Forms
'Unload each form but not the MDI until
'all others are unloaded.
If frm.Name <> Me.Name Then
Unload frm
Set frm = Nothing
End If
Next frm

'Now set the MDI form to nothing.
Set frmMDI = Nothing

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top