Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program still runs after X Click Exit 1

Status
Not open for further replies.

DK47

Programmer
Jun 3, 2003
118
US
My user just called and complained that the program I made for him on VB6 continues to run in the backround if he clicks on the X box in the upper right hand corner of the Menu Bar. (Where the minimize and maximize buttons are located.)
Since the progam uses a remote connection the connection remains open with the program in the backround.
The EXIT comand buttons I set up close the program OK but that upper right hand corner is a problem.

Any ideas on on how to connect that corner box to my code for a complete shutdown?

Thanks,
Dwight
 
can u not call your exit routine from the queryunload event?

or did i miss the point here?!?

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
To get the best response to a question, please check out FAQ222-2244 first
A General Guide To Excel in VB FAQ222-3383
 
I would suggest that you look into using the form_queryunload or form_unload event

My personal preference is to use the queryunload one.

Put yoour connection close code into either a form function /sub or module function / sub as appropriate and call that sub /function from the query unload event. to tidy up the command exit button, you will need to unload the form (unload me).

It is possible that you have an object that has not been tidied up, so it is also worth checking through the forms collection for open forms, and unloading any you find! Likewise classes and ado objects!

Some people will say "use the end" statement. This does not solve the problem, merely hides it!

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
aarg \ADoozer post clash!


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
hehe no worries!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
To get the best response to a question, please check out FAQ222-2244 first
A General Guide To Excel in VB FAQ222-3383
 
Matt and AD,
Thanks for your efforts. But.....
I think I did not make myself clear.
My Exit (command buttons) close the program without a problem.

It's that pesky little X on the menu bar that just closes the forms and modules but keeps the program running.
It is part of the form module and I have no idea how to effect it by code.
It's the same bar that holds the form caption on the left and the minimize, maximize and close "X" buttons on the right.

Thanks Again,
Dwight
 
Matt,
I sorry buddy.
I thought you did not understand my situation and so read through your response too quickly and did not realize you were putting me on the correct path.

QUestion about your response.

If I put the connection close code on a form unload or close function or event do I need to include code for every form in the program? I'm thinking the user my decide to use the X button any time in any form!!!!!
Thanks,
Dwight

Here's a star.
 
Matt,
OK I tried your tip.
It works great.


I put this code on every form in the program.
I checked windows progam running dialog box and it does shut everything down and closes any data base connections.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If Cancel <> 1 Then
End
End If
End Sub

Pretty simple, but quite effective.

Thanks Again
Dwight
 
Thanks for star, but personally I really don't like the End Statement...

It causes VB to stop (exactly the same as clicking the stop button in the IDE) It means that there is no tidying up done by either your program. This can leave DB connections and other resources, etc open... If you use subclassing and certain API techniques inappropriatley using end will cause system crashes too.

Of course, it is useful after you have done you own tidying, but I think it needs caution in its use.



Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
I'd use something like:
Code:
Public Sub UnloadAll()
  Dim frmX As Form

  For Each frmX In Forms
    Unload frmX
  Next frmX
  End
End Sub
And put it in a standard module and call it from a form's Unload event.

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
&quot;A computer program does what you tell it to do, not what you want it to do.&quot; -- Greer's Third Law
&quot;Go Bengals!&quot; -- Me
 
Matt and Andy,
Thanks to both of you.
I intend to take your advise.

I supposed that if the entire program terminated, the allocations would also.
Still have much to learn.

Regards,
Dwight


Andy,
Here's another little problem I have.
I'm a Giant's fan. Alas!!!
DK

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top