Results 1 to 6 of 6

Thread: Pressing X

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397

    Pressing X

    k, this should be a fairly easy question 2 answer....... how can i display a msgbox when the users presses X to close the form

    i have tried Query_unload and Form_unload but none where successful

  2. #2
    Fanatic Member Armbruster's Avatar
    Join Date
    Sep 2002
    Location
    Maryland Heights, MO
    Posts
    857
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     Dim intReply As Integer
    3.     intReply = MsgBox("Do you really want to quit?", vbQuestion + vbYesNo, "Quit?")
    4.     If intReply = vbNo Then Cancel = True
    5. End Sub
    "Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!

    Resistance is futile, you will be compiled . . . Please!

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Both events you mentioned are called when the user close the form. Try this code:
    VB Code:
    1. Private Sub Form_Unload(Cancel As Integer)
    2.     If MsgBox("Do you really want to close this window?", vbYesNo) = vbNo Then
    3.         Cancel = True
    4.     End If
    5. End Sub

  4. #4

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Use the QueryUnload event and check the UnloadMode parameter to check how the form is being closed.
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2. Dim strMess As String
    3.  
    4.     Select Case UnloadMode
    5.         Case vbFormControlMenu
    6.             strMess = "The user chose the Close command from the Control menu on the form."
    7.         Case vbFormCode
    8.             strMess = "The Unload statement is invoked from code."
    9.         Case vbAppWindows
    10.             strMess = "The current Microsoft Windows operating environment session is ending."
    11.         Case vbAppTaskManager
    12.             strMess = "The Microsoft Windows Task Manager is closing the application."
    13.         Case vbFormMDIForm
    14.             strMess = "An MDI child form is closing because the MDI form is closing."
    15.         Case vbFormOwner
    16.             strMess = "A form is closing because its owner is closing."
    17.     End Select
    18.    
    19.     MsgBox strMess
    20.  
    21. End Sub

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    thanks!

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