Solved

Application 'hangs around' after exit

Posted on 2006-11-15
4
686 Views
Last Modified: 2013-12-26
Hi Gurus

When a user exits my app by clicking the red close box in the top right, the app still appears in the Windows Task Manager.  If however the user goes to File, and then selects Exit, the app no longer appears in the Task Manager.

I was wondering as to what needs to happen so that my app cleanly exits, irrespective of what exit means a user has selected.

Fyi, selecting Exit from the File menu invokes the following:

Private Sub mnuFileExit_Click()
'it seems we need to keep this here (and not in the Form Unload routine above), else the app hangs
        Do Until VB.Forms.Count = 0
          Unload Forms(0)
        Loop

        Unload Me
        End
End Sub
0
Comment
Question by:BrianBeck
4 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 17946127
What ahappens if, in your form_load or form_terminate, you simply call that sub?
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 17946227
These are the unload modes :

vb constant:      Integer:      Description:


vbFormControlMenu    0    The user chose the Close command from the 'X' on the form.
vbFormCode              1     The Unload statement is invoked from code.
vbAppWindows          2     The current Microsoft Windows operating environment session is ending
                                2      the Windows OS shuts down and closes the application

vbAppTaskManager   3     MS-Windows Task Manager is closing the application.
vbFormMDIForm       4     An MDI child form is closing because the MDI form is closing.
vbFormOwner           5     A form is closing because its owner is closing.







Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    MsgBox UnloadMode
    MsgBox (UnloadMode = vbFormControlMenu)
   
    If (UnloadMode = vbFormControlMenu) Then Call mnuFileExit_Click
End Sub



Private Sub mnuFileExit_Click()
'it seems we need to keep this here (and not in the Form Unload routine above), else the app hangs
        Do Until VB.Forms.Count = 0
          Unload Forms(0)
        Loop

        Unload Me
        End
End Sub
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 17948036
If you have HIDDEN any other forms instead of closing them then the app will "hang around" after the main form has been closed.

Can you try this in the Form_Unload() event?

    Private Sub Form_Unload(Cancel As Integer)
        For Each frm In Forms
            Unload frm
        Next
    End Sub

And change your menu to?

    Private Sub mnuFileExit_Click()
        Unload Me
    End Sub
0
 

Author Comment

by:BrianBeck
ID: 17950085
Thanks to all contributors.

Idel Mind - thanks - Task Manager removes the app from its list when a user closes the "x" box or when they close using File/ Exit - great!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

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