SCENARIO
Well I started writing code for a control simulator and before I knew it I had 40 Forms and 2 Modules. It runs well when I run it in the IDE but when I made it into an exe it ran ok but when I clicked on the close button (the X in the upper right hand corner) not all of the forms closed.
So what is the best way to Close or Exit a program?
SOLUTION
What you will want to do is loop through all the forms and unload them. VB will fully close as soon as you close all forms. This is even recommended over the use of End and can be done with a snippet like the following...
Public Sub UnloadAllForms() Dim objForm As Form ' Loop through all the forms and unload each For Each objForm In Forms Unload objForm Next Set objForm = Nothing End Sub
Then all you have to do is call the function to unload all the forms loaded. I hope this is a solution that will work for you. Good luck.
SOURCE | LINK (Dreamincode.net) | LANGUAGE | ENGLISH |