Actually it is:
Child1 - Unload
Child2 - Unload
Subsequent Children - Unload
and
then MDI - Unload
>Is there anything in the MDI's QueryUnload event that would affect subsequent events?
Not really, unless you set the Cancel to vbTrue, as the forms unload between the MDI_QueryUnload and the MDI_Unload.
But this would keep the app running:
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Unload MyNonChildForm
If MyNonChildForm.Visible=False then
End If
End Sub
=============================
AndyGroom, there are some reasons this will happen, and usually it has to do with certain objects not unloading.
If you have for instance, a non-MDIChild form loaded (they do not even have to be shown), it will not get automatically unloaded, and when your application ends, it will disappear but may be still running.
To begin with, test this:
1. Start a new Project. Should have already by default a Form1 added.
2. Add a MDI Form
3. Set the Start Object to the MDI Form (Menu-Project-Properties-Start Object)
4. Add a new Form (Form2) and set it's MDIChild property to TRUE
5. Add this code to the MDI:
Code:
Option Explicit
Private Sub MDIForm_Load()
Load Form1
Load Form2
End Sub
Private Sub MDIForm_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Debug.Print "Event MDI QueryUnload"
End Sub
Private Sub MDIForm_Unload(Cancel As Integer)
Debug.Print "Event MDI Unload"
Dim frm As VB.Form
For Each frm In Forms
If (TypeOf frm Is VB.MDIForm) = False Then Debug.Print "Still loaded: " & frm.Name
Next frm
End Sub
6. Add this to Form1:
Code:
Option Explicit
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Debug.Print "Event Form_QueryUnload non-child "
End Sub
Private Sub Form_Unload(Cancel As Integer)
Debug.Print "Event Form_Unload non-child"
End Sub
7. Add this to Form2
Code:
Option Explicit
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Debug.Print "Event Form_QueryUnload child "
End Sub
Private Sub Form_Unload(Cancel As Integer)
Debug.Print "Event Form_Unload child"
End Sub
8. Run the project and then close the MDI. You will see that Form1 is still running. In the Debug Window you will see that Form1 didn't unload, and you will need to hit the Stop button on the IDE toolbar.
To make sure that at least all non-MdiChild forms are unloaded, use this in the MDI_QueryUnload:
If (TypeOf frm Is VB.MDIForm) = False Then Debug.Print "Still loaded: " & frm.Name
Unload frm
Now you will see that Form1 got unloaded and the app will actually end.