Solved

Close (X) button does not close my application.

Posted on 2004-08-14
5
178 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

786 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