Kill program FAST Help

Posted on 2002-03-19
Last Modified: 2010-05-02
My program has 3 forms, when the first one triggers the secound form to load, I hide the first.  The
problem is, if the user closes that secound or third  form, then the first/Second one still exists but is hidden so you have to go into the task manager to close it.  
Need help fast for this question please
Question by:bojman
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
  • 2
LVL 39

Expert Comment

ID: 6881958
in a bas module add the following sub

public sub CloseApplication()
for intCnt =forms.count to 1 step -1
   unload forms(intCnt)
next intCnt
end sub

use CloseApplication whenever you want to close all

Accepted Solution

Moogy earned 300 total points
ID: 6881963
It's the job of the programmer to keep track of all objects and clean things up, so you'll need to write some code to regulate this.

Using the End statement is an easy way to shut things down, but it can be dangerous and doesn't always clean things up.  I recommend against it.

What I recommend is creating a shutdown procedure that cycles through the loaded forms and unloads all of them.  you can execute this feature when the user shuts down a form, or executes an exit.

An example:

Do While Forms.Count > 0
 Unload Forms(0)

You can also walk the forms collection when another form is unloaded or hidden and find out if all of the forms are hidden - if so, then shut down.  For example:

Dim bVisible as boolean
Dim iLoop as Integer

For iLoop = 0 to Forms.count - 1
 if forms(iLoop).Visible then
   exit for

if bVisible = false then
 ' Unload everything...

I hope this helps!

LVL 39

Expert Comment

ID: 6881964
sorry use this
public sub CloseApplication()
for intCnt =forms.count-1 to 0 step -1
  unload forms(intCnt)
next intCnt
end sub

LVL 52

Expert Comment

by:Ryan Chong
ID: 6881973
LVL 52

Expert Comment

by:Ryan Chong
ID: 6881975
Sorry as didn't see Moogy already post it.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

724 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