Results 1 to 9 of 9

Thread: not unloading my app if Cancel is picked

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    not unloading my app if Cancel is picked

    ?
    how do i do this?

    if the user clicks the big 'X' in the upper right corner, i want to ask if they want to close.

    if yes unload me
    else
    'what here?
    end if

    i have no clue so any suggestions would be super cool.

    thanks
    pnj

  2. #2
    Hyperactive Member Jason Badon's Avatar
    Join Date
    Feb 2001
    Location
    Colorado
    Posts
    329
    I THINK THIS SHOULD WORK..

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    prompt$ = "ARE YOU SURE YOU WANT TO EXIT?"
    reply = MsgBox(prompt$, vbYesNo, "EXIT")
    If reply = vbYes Then
    Unload Me
    Else
    Cancel = True
    End If
    End Sub

  3. #3
    Addicted Member bbosh's Avatar
    Join Date
    Oct 2000
    Location
    Hell (AKA New Mexico)
    Posts
    186
    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
         If UnloadMode = 1 Then
              X = MsgBox("Are you sure you want to exit?", vbYesNo)
              If X = vbYes Then
                   ' Unload Code Here
              Else
                   Cancel = 1
              End if
         Else
              ' OS Is forcing close, put forced exit code here
         End If
    End Sub
    Last edited by bbosh; Jun 10th, 2001 at 01:14 AM.
    Brian
    Programming: VB5 Pro (SP3) - QBasic 1.1,4.5
    Internet: HTML 4, CSS, JavaScript
    Visit AltInt.com!

  4. #4
    Lively Member Blaster's Avatar
    Join Date
    Jun 2001
    Posts
    70
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If MsgBox("Do really want to quit?", vbQuestion Or vbYesNo, "Quit?") = vbNo Then
    Cancel = 1
    End If
    End Sub

  5. #5
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Query Unload event details:

    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Select Case UnloadMode
        Case vbFormControlMenu ' =0 closed by user
        Case vbFormCode ' =1 form closed by code
        Case vbAppWindows ' =2 windows is ending
        Case vbAppTaskManager ' =3 task manager is closing
        Case vbFormMDIForm ' =4 mdi parent is closing
        Case vbFormOwner ' =5 the owner form is closing
    End Select
    End Sub

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    thanks all!!!
    pnj

  7. #7
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192

    Question

    What do I have to do for making the "No" or "cancel" button as the default button ?

  8. #8
    Addicted Member bbosh's Avatar
    Join Date
    Oct 2000
    Location
    Hell (AKA New Mexico)
    Posts
    186
    X = Msgbox("Are you sure you want to exit?", vbyesnocancel or vbdefaultbutton2) ' No is default
    X = Msgbox("Are you sure you want to exit?", vbyesnocancel or vbdefaultbutton3) ' Cancel is default
    Brian
    Programming: VB5 Pro (SP3) - QBasic 1.1,4.5
    Internet: HTML 4, CSS, JavaScript
    Visit AltInt.com!

  9. #9
    Addicted Member
    Join Date
    Apr 1999
    Location
    Ruinen, Drente, Netherlands
    Posts
    192
    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