Results 1 to 7 of 7

Thread: Application is still running after close

  1. #1

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    Anybody had this before?

    I have an application that Ends with a command button something like this

    Command1_Click()
    Unload Me
    End
    End Sub

    Then I can CTRL+ALT+DEL and the program is still running even after I have exited through the command button.

    This application is already in .EXE format if that makes any difference.

    Thanks.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If you have any forms still loaded in memory or any loops still executing with DoEvents in them then the application won't close. Make sure all loops exit and try:
    Code:
    Private Sub Command1_Click()
        Dim oForm As Form
        For Each oForm In Forms
             If oForm.Name <> Me.Name Then Unload oForm
        Next
        Unload Me
    End Sub

  3. #3
    Guest
    You may also want to do something like Set Form1 = Nothing to rid any resources it uses.

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Sometimes unloading forms just isn't enough...

    If you created a form as an instance of the object, used it then you need to make sure you set the variable back to "nothing" even after you have unloaded it.

    Code:
    Dim frmMine as New MyForm
    
    MyForm.Show vbModal
    
    Unload MyForm
    Set MyForm = nothing
    If you have done this "EVERY" time you created a new form then it should close correctly... it hangs around (which you should notice hangs around in your development environment because it doesn't stop even when you close the last form) because it still thinks there is something going on inside with a form that is just hidden, or unloaded but still active.

    Rather than do the check through forms at the end I would carefully study your code to find out where you are NOT unloading it, Better to fix the source than always try to tidy up sloppy coding at the end.

  5. #5

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    thanks

    all sound like good advice


    thanks all

  6. #6

    Thread Starter
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604

    X box closing

    oh, sorry

    one last question



    Does closing an application via the X box also unload all forms in the application?

  7. #7
    Guest
    The X button is refered to in the Query_Unload statement..anything put there will do something when you click the X button.

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