Results 1 to 4 of 4

Thread: How use code when using the X to close a form ? (solved)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Belgium
    Posts
    77

    How use code when using the X to close a form ? (solved)

    Hi, I need to be able to put some code when the user close a windows with the "X" cause otherwise the form behind isn't enabled back and programme is freezed. When the user close the windows using my button i just have to put :

    frmMain.enabled = True

    But if he use the X how can I do ?
    Last edited by choas; Feb 21st, 2004 at 01:15 PM.

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    Use the Terminate or Unload Event. Unload fires first, then Terminate.

    Example

    VB Code:
    1. Private Sub Form_Terminate()
    2. MsgBox "Bye Terminate"
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6. MsgBox "Bye Unload"
    7. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You might want to consider using the QueryUnload event.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.  
    3.     Select Case UnloadMode
    4.         Case vbFormControlMenu
    5.             strMess = "The user chose the Close command (the "X") from the Control menu on the form."
    6.         Case vbFormCode
    7.             strMess = "The Unload statement is invoked from code."
    8.         Case vbAppWindows
    9.             strMess = "The current Microsoft Windows operating environment session is ending."
    10.         Case vbAppTaskManager
    11.             strMess = "The Microsoft Windows Task Manager is closing the application."
    12.         Case vbFormMDIForm
    13.             strMess = "An MDI child form is closing because the MDI form is closing."
    14.         Case vbFormOwner
    15.             strMess = "A form is closing because its owner is closing."
    16.     End Select
    17.  
    18. End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Location
    Belgium
    Posts
    77
    Thanks, the unload query work fine, but it seem terminate and unload event don't.

    Anyway thanks to both of you. I gonna put this topic as solved

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