Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

N00b msgbox question

Status
Not open for further replies.

dgillz

Instructor
Mar 2, 2001
10,045
US
I have a Message box snippet of code:

Code:
MsgBox("Ready to continue?)

However this just presents the user an "OK" button. I need to display 2 buttons, Yes and No.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"If you have a big enough dictionary, just about everything is a word"
--Dave Barry
 
Put the cursor inside the MsgBox word in your code and press the F1 key.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have already done this. I see the vbYesNo suggested, but I cannot get it to work. The suggested syntax:

MsgBox(prompt[, buttons] [, title] [, helpfile, context])

Does not work in the 5 or 6 tries I have already attempted.

Anything beyond asking me to look at the help files is appreciated. Maybe some sample code?




Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports

"If you have a big enough dictionary, just about everything is a word"
--Dave Barry
 
A starting point:
If MsgBox("Ready to continue?", vbYesNo) <> vbYes Then
Exit Sub
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
MsgBox(prompt[, buttons] [, title] [, helpfile, context])

Does not work in the 5 or 6 tries I have already attempted.
It would also be helpful (and is generally a good rule) that when you mention "tries", that you actually post the code you did try.

MsgBox("Ready to continue?", vbYesNo) (from PHV, which does work) does not look all that different from

MsgBox("Ready to continue?) - which you say you trued.

Although....it does need the "" at the end.

faq219-2884

Gerry
My paintings and sculpture
 
Hi dgillz:

Here is an illustration that might be of some help ...
Code:
Sub y_2()
    'May-27-2007 Yogi Anand
    msg1 = MsgBox("Ready to continue?", vbYesNoCancel)
    If msg1 = vbYes Then
        '... the part if Yes was pressed
        ElseIf msg1 = vbNo Then
        '... the part if No was pressed
        Else
        '... the part if Cancel was pressed
    End If
End Sub

Yogi Anand, D.Eng, P.E.
Energy Efficient Building Network LLC
 
OR...
Code:
Dim msg1 As VbMsgBoxResult
    msg1 = MsgBox("Ready to continue?", vbYesNoCancel)
    Select Case msg1
      Case 6
        '...Yes was pressed
      Case 7 
        '...No was pressed
      Case 2
        '...Cancel was pressed
    End Select
Note that the value 2 is returned by both the actual Cancel button, and clicking the "x" Close button.

You can use either the number, or the text (eg. 6, or vbYes) in your code. Most people use the text. However, there are circumstances when you may want to know the history of the messagebox use. By using a counter, and the accumulated value of the response, you can get that history. Although not the order.

Eg.
accumulated value = 6, counter = 3
The messagebox was used three times, Cancelled everytime ( 2 + 2 + 2)

accumulated value = 6, counter = 1
The messagebox was used once, Yes was clicked

accumulated value = 21, counter = 4
The messagebox was used 4 times, two Yes, one No, one Cancel

accumulated value = 21, counter = 3
The messagebox was used 3 times, three No

etc. etc.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top