Solved

Close (X) button does not close my application.

Posted on 2004-08-14
5
181 Views
Last Modified: 2010-05-02
My program terminate command is as follows:
  Form1.Hide
  Unload Form1
  End
This works well every time. However, when I use the windows standard (X) button in the upper right hand corner of the window, the application becomes invisible but remains running. The application appears in the task manager and can only be closed using "End Task". The average user will always use the (X) as a way to exit any application. How do I get the (X) button to terminate my program?
Thanks
0
Comment
Question by:StephenMShick
[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
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 250 total points
ID: 11803236
Hi,
Add End statement to QueryUnload events of forms that you want to click on their (X) button and terminate your program.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    End
End Sub

-FA
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 11803247
The "End" is not a very good thing to be used as this stops the program abrubtly .. no cleaning of variables .. memory etc happens after the command .. use this code .. remove the ".Hide" .. it is not necessary for u to close the form ...

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   unload form1
   set form1 = nothing
End Sub
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 11803313
ok cool .. u have anway accepted an answer .. but i will still say the "End" is not a nice solution ..understand y ur code was not working ... it was becuase the terminate event was not geting executed .. when u "unload form1" it does not really remove it from the memory .. using the set form1 = nothing would ensure that .. so ur code would still continue to work if u have this statement ..
0
 

Author Comment

by:StephenMShick
ID: 11804175
Thanks to FarzadA and Rejojohny
I used a combination of both answers as shown below.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   Unload Form1
   Set Form1 = Nothing
   End
End Sub

Unfortunately I ould only officially accept one answer. I selected the first because it did stop the program. The second answer did the clean up, but left it running. Still need the "End".
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 11804204
the program was still running because some objects created within ur code is still "alive" probably becuase of the form1.hide method .. try removing it .. and without the "end" statement .. I am sure it will work ...

as i said .. the "END" statement has just ended everything at the spot .. that is not really a good solution .. basically u have not exited gracefully ...

have a look at these posting too
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21024448.html
(arthur's comment)

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

719 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