Results 1 to 3 of 3
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    mdi form and unload statement (6.0)

    Why when i choice "no" from the msgbox the code close the form ???
    In effect if the answhere is Yes exit and close the form, if i choice "No" reamin active the form...
    Private Sub MDIForm_Unload(Cancel As Integer)

    On Error GoTo errore

    DOMANDA = Empty
    DOMANDA = MsgBox("SEI SICURO DI VOLER USCIRE?", vbYesNo, "..:: PAST DUE ::..")

    If DOMANDA = vbYes Then
    If Not CNSQL1.State = adStateClosed Then
    CNSQL1.Close
    GoTo FINE
    End If
    Else
    Exit Sub
    End If

    FINE:
    End 'esce dall'esecuzione dell'istanza,
    'senno il codice successivo sarebbe
    'stato eseguito
    errore:
    MsgBox "errore numero: " & CStr(Err.Number) 'CStr serve a convertire
    'un valore in stringa
    MsgBox "descrizione: " & Err.Description
    MsgBox "sorgente dell'errore: " & Err.Source

    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: mdi form and unload statement (6.0)

    Your MsgBox is followed immediately by End Sub. If you want your procedure to continue after the MsgBox is displayed, you need to use a Resume statement.

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: mdi form and unload statement (6.0)

    I cannot see ANY reference to forms anywhere in this code at all!

    It's a bit easier to see what is happening if you indent your code, like this...
    <code>
    DOMANDA = MsgBox("SEI SICURO DI VOLER USCIRE?", vbYesNo, "..:: PAST DUE ::..")
    If DOMANDA = vbYes Then
    If Not CNSQL1.State = adStateClosed Then
    CNSQL1.Close
    GoTo FINE
    End If
    Else
    Exit Sub
    End If
    </code>

    If the user answers NO to the message box then you could simplify this to
    <code>
    DOMANDA = MsgBox("SEI SICURO DI VOLER USCIRE?", vbYesNo, "..:: PAST DUE ::..")
    If DOMANDA = vbYes Then
    <font color=448800>'</font color=448800>
    Else
    Exit Sub
    End If
    </code>

    So if the user doesn't answer YES you go straight to the Exit Sub command.

    StuartR

Posting Permissions

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