Results 1 to 4 of 4

Thread: How do I code my program to detect app termination from the upper right "X" ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    25
    How do I code my program to detect sudden app termination from the upper right "X" ?

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124
    Try using this code and see if it works for your situation.

    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    
    
        Select Case UnloadMode
            Case vbFormControlMenu
                MsgBox "The user chose the Close command from the Control menu on the form."
            Case vbFormCode
                MsgBox "The Unload statement is invoked from code."
            Case vbAppWindows
                MsgBox "The current Microsoft Windows operating environment session is ending."
            Case vbAppTaskManager
                MsgBox "The Microsoft Windows Task Manager is closing the application."
            Case vbFormMDIForm
                MsgBox "An MDI child form is closing because the MDI form is closing."
            Case vbFormOwner
                MsgBox "A form is closing because its owner is closing."
        End Select
    
    
    End Sub
    The vbControlMenu is what was passed to the QueryUnload event when I clicked the "X" in the upper right hand corner and when I went to the control menu clicked close.

    If you have an exit on your menu bar or a command button the vbFormCode will be passed in.


    Is this what your looking for?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    25

    That was pretty neat.

    Thanks.
    To answer your question, what i was looking for was to ensure that if at anytime , if somewhere in my prgram the user closes the program using the "X" that my program will actually close properly and release it's influence on the system's resources.

    Thanks for your help.

  4. #4
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    You can also put code in the Form_Unload event to clean up any open objects, etc.
    JC

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width