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
Solved

Kill program FAST Help

Posted on 2002-03-19
5
166 Views
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
0
Comment
Question by:bojman
  • 2
  • 2
5 Comments
 
LVL 39

Expert Comment

by:appari
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
0
 
LVL 1

Accepted Solution

by:
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)
Loop

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
   bVisible=true
   exit for
 Endif
Next

if bVisible = false then
 ' Unload everything...
endif

I hope this helps!




0
 
LVL 39

Expert Comment

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

0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6881973
End
0
 
LVL 50

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

839 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