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

code to detect when an App has been closed

What's the code/syntax to detect if someone shuts down an App using the close button in the upper right corner,
versus exit in the file menu, which is just end. The system resources are getting locked up.
Thanks!
0
jim24
Asked:
jim24
  • 4
  • 2
1 Solution
 
tkuppinenCommented:
It is the form unload event which always occurs when the x button is pressed.
0
 
tkuppinenCommented:
Try this as an example.
Private Sub Form_Unload(Cancel As Integer)

msgbox "unloading"
End Sub

within this event you can write code which will free up your system resources.

You can also wirte code which will make that little x become disabled when you run your project.
0
 
Erick37Commented:
In the QueryUnLoad event check the value of the UnloadMode variable:

vbFormControlMenu = 0 The user chose the Close command from the Control menu on the form. Or [X] button.
vbFormCode = 1 The Unload statement is invoked from code.
vbAppWindows =2 The current Microsoft Windows operating environment session is ending.
vbAppTaskManager = 3The Microsoft Windows Task Manager is closing the application.
vbFormMDIForm = 4 An MDI child form is closing because the MDI form is closing.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
tkuppinenCommented:
One last thing.  I will provide you with the code to disable that little x if you would like.
0
 
tkuppinenCommented:
Didn't mean to answer so quickly, fell free to reject the answer.
0
 
Erick37Commented:
P.S.
Do not use END in your application to terminate it.  Use instead:
Unload Me
which will free the resources and trigger the QueryUnload and Unload events.
0
 
jim24Author Commented:
Thank You Very Much!!!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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