Solved

Application 'hangs around' after exit

Posted on 2006-11-15
4
685 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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