To reproduce this problem, create a new form and have this code in
appropriate events.
Private Sub Form_Close()
Debug.Print "Closing..."
End Sub
Private Sub Form_Resize()
Debug.Print "Resizing..."
End Sub
Private Sub Form_Unload(Cancel As Integer)
Debug.Print "Unloading..."
End Sub
If the form is not maximized, the order of
events you should receive is
Resizing -> Unloading
-> Closing
But for maximized forms, this becomes
Unloading -> Closing -> Resizing
So, if you have a module level object variable that you're
calling from the Resize event, and if you set it to Nothing from the form's
Close event, you will likely receive Error 91 (Object variable or With block variable not set).
The workaround is to use code in the Resize event only if
a module-level boolean variable is False; and set it to true from the
form's Close event.
|