Link to home
Start Free TrialLog in
Avatar of razvanl
razvanl

asked on

Unloading all forms before exiting

Hi,

I would like to know if there is a way to unload all the loaded forms in a program when you exit.  Other than typing 20 or so unload formname, is there another solution?

I am under the impression that VB doesn't exactly do a good cleanup after you close a program, and on some computers it gives a crash in module <unknown> (which helps a lot).  I suspect that this may be caused by some parts of the program remaining loaded in memory.

Sincerely,
Razvan Loghin
ASKER CERTIFIED SOLUTION
Avatar of edunc
edunc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of caraf_g
caraf_g

edunc's code is fine - give him/her the points; but to ensure proper functionality even when some windows are shown modally make sure to unload the topmost windows first

The topmost window can be accessed as ActiveForm

Dim objAF As Object

Set objAF = Screen.ActiveForm
do while not ofjAF Is Nothing
    Unload objAF
    Set objAF = Screen.ActiveForm
loop

then follow with edunc's code to unload any remaining hidden forms.