Solved

Unloading all forms before exiting

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

615 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