Solved

Unloading all forms before exiting

Posted on 1999-01-10
2
167 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:razvanl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
edunc earned 50 total points
ID: 1455204
if you use the End statement to end your program then that will happen sometimes.
use this code to unload all the forms that are loaded:

  Do Until VB.Forms.Count = 0
    Unload Forms(0)
  Loop
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1455205
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.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question