Solved

Unloading all forms before exiting

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Public Sub, Empty Cell 7 56
VB6 convert MSHFlexgrid1 cells no2 2 50
VBA open file from excel cell 4 33
vb6 connector to mongodb 2 26
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now