Results 1 to 3 of 3

Thread: MsgBox Help

  1. #1
    New Member
    Join Date
    Feb 05
    Posts
    4

    Question MsgBox Help

    How do I make my MsgBox return a particular result? I have a vbYesNo msgbox, where i want if "Yes" is clicked then a form will open else if "No" is clicked, the message box closes and no changes are made.

    I'm very new to VBA so please excuse my lack of knowledge. Thankingnyou in advance.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 00
    Location
    Excel Hell!
    Posts
    4,895

    Re: MsgBox Help

    Type MsgBox in the code window and press f1.

    Basically it this :

    Msgbox "Message",<buttons> + <icons>,"Title" <<< Displays the message only
    Msgbox ("Message",<buttons> + <icons>,"Title") <<< Is a function thus returns the button pressed

    So your code would be something like:
    Code:
        Dim lngRes as long
    
        lngRes = -1
        lngRes = Msgbox("The test message",vbyesno+vbexclamation,"Title here")
    
        if lngRes = vbyes then
    '---- do yes stuff
        else
    '---- do no stuff
        end if
    Help file has the variables / values

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    Lively Member
    Join Date
    Sep 04
    Posts
    74

    Re: MsgBox Help

    VB Code:
    1. if Msgbox("The test message",vbyesno+vbexclamation,"Title here") = vbYes then
    2.      'do yes stuff
    3. else
    4.      'do no stuff
    5. endif

    is quicker ;-)

Posting Permissions

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