Solved

Unloading all forms before exiting

Posted on 1999-01-10
2
161 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 53
clicking a shape in a frame array vb6 3 45
vbModal 12 51
VBA - If Bookmark = "XXBOOKMARKXX" then 15 25
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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 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