Message Boxes

KevCB226

Registered User.
Local time
Today, 14:04
Joined
Oct 20, 2005
Messages
24
Hi

Is it possible to set events for the buttons on a message box?
For example if I create a Message Box when someone clicks on a button, and set it to vbYesNo, can I then create an open form event on the yes button, and a close acform event on the no button.

Thanks
 
Yes.

Dim MyReply As Integer
MyReply=MsgBox("Yes or No?",vbYesNo,"Question")
If MyReply=6 Then '6 = Yes'
Do some action for the Yes response
Else
Do some action for the No response 'No = 7'
End If

HTH

Dave E
 
Dave Eyley said:
If MyReply=6 Then '6 = Yes'

Or, rather than knowing the numbers you can use the enumerated constant:

i.e.

Code:
If MyReply = vbYes Then
 
I usually use this one, it's faster and simpler when you set up the msgbox on the same time I think:

If MsgBox("Message here", vbYesNo) = vbYes Then
...
 
"If MsgBox("Message here", vbYesNo) = vbYes Then"

I like that one, ailyn


Dave E
 
Yeah, it's sometimes nice to read it but there can be instances where you need to store the MyReply for evaluations further along in the code without having to ask the user each time.
 

Users who are viewing this thread

Back
Top Bottom