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!
jim24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tkuppinenCommented:
It is the form unload event which always occurs when the x button is pressed.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.