Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2007
    Posts
    70

    Unanswered: Getting msgbox to function?

    Hi,

    I have a msgbox using vbYesNo. How can I differenciate between then in vb code? I've got the following code below but can't get it to work!

    Code:
     MsgBox "Do you want to continue?", vbYesNo
        
        If vbYesNo = False Then
            GoTo Exit_close_frm_zo_reports_Click
        Else
            DoCmd.Close
        End If
    Am i way off?

    Cheers

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quote Originally Posted by OB1
    Am i way off?
    Yup

    You can treat the msgbox method like a function and store the return in a numeric variable. Then test the variable to see if it matches one of the enumerations (If myvar = vbYes Then....)

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    or even
    MsgBox "Do you want to continue?", vbYesNo

    Code:
        If MsgBox ("Do you want to continue?", vbYesNo) = vbyes Then
            GoTo Exit_close_frm_zo_reports_Click
        Else
            DoCmd.Close
        End If

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Yeppers - although of course if you ask a non boolean question you'll need to use a variable (that's for the OP Mark - I know you'll know that )

  5. #5
    Join Date
    Dec 2007
    Posts
    70
    Quote Originally Posted by healdem
    or even
    MsgBox "Do you want to continue?", vbYesNo

    Code:
        If MsgBox ("Do you want to continue?", vbYesNo) = vbyes Then
            GoTo Exit_close_frm_zo_reports_Click
        Else
            DoCmd.Close
        End If
    I've put this into the code and it works but you have to click the msgbox twice for it to take effect? On the yes or no.

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    What is the code in its entirity?

  7. #7
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Wink try this 1 for size

    Code:
    dim vbResult as msgboxresultset
    
    retry:
    vbResult=msgbox("Do you want to save",vbyesNo+vbquestion,"Save")
    
    Select case vbResult
       case vbyes
            'Save doc
       case vbNo
           vbResult=msgbox("Are you sure ;-) ",vbyesNo+vbquestion,"Save")
            if vbResult =vbNo then goto retry
            'Don't Save doc
       case Else 'esc was pressed or something
            'Don't Save doc
    end select
    Last edited by Marvels; 02-21-08 at 08:09.
    Greetz Marvels -^.^-
    Developments : VB4 Through .Net; Basic; DOS ; CNC ; Sinclair
    Databases : SQL Server Through 2005; Access 3 Through 2003 ; Oracle 8 & 9.i ;
    OS : Win 3.11 Through XP ; NortonComander ; DOS

  8. #8
    Join Date
    Dec 2007
    Posts
    70
    This is the whole code:
    Code:
    Private Sub close_frm_zo_reports_Click()
    On Error GoTo Err_close_frm_zo_reports_Click
    
    
        MsgBox "Do you want to continue?", vbYesNo
        
        If MsgBox("Do you want to continue?", vbYesNo) = vbNo Then
            GoTo Exit_close_frm_zo_reports_Click
        Else
            DoCmd.Close
        End If
        
            
    
    Exit_close_frm_zo_reports_Click:
        Exit Sub
    
    Err_close_frm_zo_reports_Click:
        MsgBox Err.Description
        Resume Exit_close_frm_zo_reports_Click
        
    End Sub

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    take out the first msgbox..... thats why its repeating
    effectively you are asking the same question twice.. you only need to do it in the If statement. the first one asks the question of the user, but does nothing with the user response

  10. #10
    Join Date
    Dec 2007
    Posts
    70
    Doh!!!

    Cheers healdem

Posting Permissions

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