Proper way to shut down program?

When shutting down a program of mine by clicking the Close button in the upper right or double clicking the icon in the upper left the program looks as if it shuts down. It's not a 'proper' shutdown, the program is still running sub processes but I need it to close. In Task Manager I can see it still running. One part of the program is to send text to a website's table  in the webbrowser object. After shutting the program down, it's still trying to send text to whatever window I've got open. I have to go into the task manager / Applications tab and close it out from there. I would just insert a command button with 'end' it in but I believe that's the same thing as closing the program out the way I do now. Any help would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dim frm as object

for each frm in form
 set frm = nothing

never use the end command in shutingdown a program the proper way is to unload all the forms then set all form to nothing. :)
Try putting some code in the form's QueryUnload, Unload or Terminate events.  When the user clicks 'Close', those events are fired in that order.

In QueryUnload you have an UnloadMode parameter that you can use to tell why your form is closing (windows shutdown, killed from task manager, closing normally, user clicked close in top corner, etc).

Then you can take appropriate action ... halt your background processing, prevent the close, etc.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

btw: Unloading all the forms will not necessarily end a program.  (eg, if program was started from Sub Main or has other threads of execution).
ensure all forms are unloaded, all DB.connections closed etc

I use I little routine (shortened sample below) that I call on the mainform unload event

Public Sub Finishup()
'Tidy up all objects.  May already be closed/unloaded

On Error Resume Next
    'release all collections
    Set gcolWhatever = Nothing
     Set gconnDB = Nothing    
End Sub
Of course, to just kill everything your app is doing (the equivalent of End Process from the task manager), just put End in the form's Unload event.

This IS safe and fine to do as long as your app doesn't use any resources (such as DB) that should be closed and disposed of.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
(sorry ... hit submit too soon)

... and you don't have code that you need executed as your forms are unloading.

From Microsoft's VB6 Language Reference;

Note   The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.

The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing.
I think you'll find that just using end is fine, unless there are more than one form open in your app..

Each form needs to be unloaded before firing the end command.

I use the following;

    Static unloadForm As Boolean
    Dim i As Integer
    If unloadForm Then Exit Sub
    unloadForm = True
    i = Forms.Count
    For i = Forms.Count - 1 To 0 Step -1
        Unload Forms(i)
    Next i
End If

Which I picked up somewhere on the web..

Leo EikelmanDirector, IT and Business DevelopmentCommented:
This is the proper way of shutting down

Dim frm as Form

    ' Loop thru the forms collection and
    ' unload all forms from memory
    For Each frm In Forms
          frm.Hide            ' hide the form
          Unload frm          ' deactivate the form
          Set frm = Nothing   ' remove from memory      


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.