• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

Form not executing the unload event

Can anyone think of a reason why when I click the X in the upper right hand corner of my form the unload event doesn't get executed?
3 Solutions
Carl TawnSystems and Integration DeveloperCommented:
Only reason I can think of could be if the QueryUnload event was firing and was coded to cancel the unload.
BofADevAuthor Commented:
The problem was I was clicking the x on the mdi parent form instead of the child where I was trying to see the unload event.  Still though I would have thought it would have fired each mdi child form's unload event...oh well :)

So what is the difference between QueryUnload and Unload?  Which fires first?
jkaiosIT DirectorCommented:
To find out the "order" of which event gets fired first:

1) Create a new project with a new form

2) Put codes in the following form events to print the event name to the Immediate Window
      Private Sub Form_Deactivate()
         Debug.Print "Deactivate"
      End Sub
      Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
         Debug.Print "QueryUnload"
      End Sub
      Private Sub Form_Terminate()
         Debug.Print "Terminate"
      End Sub
      Private Sub Form_Unload(Cancel As Integer)
         Debug.Print "Unload"
      End Sub

3) Run your project

4) End the project

5) Now bring up the Immediate Window to see which event got fired first
You can use the form_unload() event and write your code to unload the form in this event

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now