I'm looking for a message box that if you select yes, something happens or no something else happens.
Any good examples?
Private Sub cmdMessageBox_Click()
MsgBox "Your logon credentials have been checked " & _
"and your application has been approved: Congratulations!" & _
vbCrLf & "Before leaving, would you like " & _
"to take our survey survey now?", _
VbMsgBoxStyle.vbYesNo Or VbMsgBoxStyle.vbQuestion
End Sub
if you select yes, something happens or no something else happens.
Private Sub msgDemo()
Dim rtn As Long
rtn = MsgBox("Your logon credentials have been checked and your application has been approved: Congratulations!" & vbCrLf & "Before leaving, would you like " & _
"to take our survey survey now?", _
VbMsgBoxStyle.vbYesNo Or VbMsgBoxStyle.vbQuestion)
If rtn = vbYes Then
'do code here for yes
Debug.Print vbYes
Else
'do some code here for NO
Debug.Print vbNo
End If
End Sub
if msgbox ("pressing yes will catastrophically delete all of your data. " & vbcrlf & vbcrlf & _
"Do you want to continue? ", vbQuestion + vbYesNo + vbdefaultbutton2,"Confirm Action")= vbno then
exit sub
end if
The name of this technique escapes me for the moment!!!!
Obfuscation
It's commonly called addition. - The opposite of subtraction. ;-)The name of this technique escapes me for the moment!!!!
These times might become less rare, if you consider that code is read much more often than written. A 10/1 ratio is often assumed.It is one of the rare times when I think that something that makes you type MORE is preferable to something that lets you type LESS.
I am no expert on this, but AFAIK it is called a bitmask and not obfuscation.The name of this technique escapes me for the moment!!!!
vbRetryCancel | 5 | 00000101 |
vbQuestion | 32 | 00100000 |
vbDefaultButton2 | 256 | 10000000 |
5 | 00000101 |
and 293 | 10100101 |
5 | 00000101 |
32 | 00100000 |
and 293 | 10100101 |
32 | 00100000 |
256 | 10000000 |
and 293 | 10100101 |
256 | 10000000 |
bitmask
Note that you can choose to pre=select whichever option you want - generally the non-destructive answer will be best, so users won't inadvertently err just pressing enter. eg the follow makes NO the default action.
Code:if msgbox ("pressing yes will catastrophically delete all of your data. " & vbcrlf & vbcrlf & _ "Do you want to continue? ", vbQuestion + vbYesNo + vbdefaultbutton2,"Confirm Action")= vbno then exit sub end if
As @MajP noted, you can use or or + to show multiple buttons is fine.
The main bubble options are vbQuestion, vbInformation, vbExclamation and vbCritical. You can only have one of these.