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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I tell what button in a message box the user clicked? 1

Status
Not open for further replies.

PockyBum522

Programmer
Jun 10, 2003
239
US
I have a message box with yes and no for buttons, if the user clicks yes I want to run some code, and if he clicks no, I just want the message box to go away.

How?

Thanks!
 
MsgBox is a function that returns an integer indicating which button was pressed. Put the cursor on MsgBox and press F1.

Constant Value Description
vbOK 1 OK
vbCancel 2 Cancel
vbAbort 3 Abort
vbRetry 4 Retry
vbIgnore 5 Ignore
vbYes 6 Yes
vbNo 7 No

For Help, Put the cursor on MsgBox and press F1.



Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
As JohnYingling told above you can simply check msgbox return value. For example:

---------------
Dim ReturnAnswer As Integer

ReturnAnswer = MsgBox("Are you sure?", vbYesNo, "Confirm")

Select Case ReturnAnswer
Case vbYes: ' Answer is Yes
Case vbNo: ' Answer is No
Case vbOK: ' Answer is Ok
Case vbCancel: ' Answer is Cancel
End Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top