Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUnload an application's forms in reverse order of creation, skipping any that don't unload
DescriptionThis example shows how to unload an application's forms in reverse order of creation in Visual Basic 6.
Keywordsclose, unload, form
CategoriesSoftware Engineering, Controls
 
This program's forms have a combo box labeled "Don't Close." The QueryUnload event handler checks its value and refuses to let the form unload if the combo box is checked.
 
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode _
    As Integer)
    Cancel = (cboDontClose.Value = vbChecked)
End Sub
 
Click the New button to make a new instance of the program's form. Click the Close All button to run the following code, which loops through the Forms collection unloading the forms, most recently created first. If any form fails to unload, the loop simply continues with the next form.
 
Private Sub cmdCloseAll_Click()
Dim i As Integer

    For i = Forms.Count - 1 To 0 Step -1
        Unload Forms(i)
    Next i
End Sub
 
See also:

 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated