Title | Unload an application's forms in reverse order of creation, skipping any that don't unload |
Description | This example shows how to unload an application's forms in reverse order of creation in Visual Basic 6. |
Keywords | close, unload, form |
Categories | Software 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:
|
|
|
|