Section B.7. Message Box Constants
B 7 Message Box Constants
Except for vbMsgBoxHelpButton, any one of the following constants can be used with the buttons parameters of the MsgBox function to determine which buttons appear in the dialog. The vbMsgBoxHelpButton constant can be ORed with the button constant to add a Help button to provide context-sensitive help; this, however, also requires that arguments be supplied to the function's helpfile and context parameters.
Constant |
Value |
Description |
---|---|---|
vbAbortRetryIgnore |
2 |
Abort, Retry, and Ignore buttons |
vbMsgBoxHelpButton |
16384 |
Help button |
vbOKCancel |
1 |
OK and Cancel buttons |
vbOKOnly |
0 |
OK button; this is the default value |
vbRetryCancel |
5 |
Retry and Cancel buttons |
vbYesNo |
4 |
Yes and No buttons |
vbYesNoCancel |
3 |
Yes, No, and Cancel buttons |
You can determine which of these buttons is the default (that is, it appears selected and will be chosen if the user presses the Enter key) by logically ORing any one of the following constants with any other constants passed to the buttons parameter. The selected button is designated by its position on the dialog. By default, the first button appears selected.
Constant |
Value |
Description |
---|---|---|
vbDefaultButton1 |
0 |
First button is the default |
vbDefaultButton2 |
256 |
Second button is the default |
vbDefaultButton3 |
512 |
Third button is the default |
vbDefaultButton4 |
768 |
Fourth (Help) button is the default |
The MsgBox function also allows you to designate an icon that appears in the message box to indicate the message type. You can logically OR any one of the message box icon constants with the other values that you pass as arguments to the buttons parameter, as in the following code fragment:
iResult = MsgBox("Is this OK?", vbYesNo Or vbQuestion Or _ vbApplicationModal, "Delete File")
Constant |
Value |
Description |
---|---|---|
vbCritical |
16 |
Critical (stop sign) icon |
vbExclamation |
48 |
Exclamation (caution) icon |
vbInformation |
64 |
Information icon |
vbQuestion |
32 |
Question mark icon |
You can also determine the modality of the message box by ORing one of the following constants with any other constants passed to the buttons parameter:
Constant |
Value |
Description |
---|---|---|
vbApplicationModal |
0 |
The focus cannot move to another interface object in the application until the dialog is closed. |
vbSystemModal |
4096 |
The focus cannot move elsewhere in the system until the dialog is closed. |
Three miscellaneous constants can be used to control the behavior of the dialog. Once again, they must be logically ORed with any other constants passed to the buttons parameter.
Constant |
Value |
Description |
---|---|---|
vbMsgBoxRight |
524288 |
Right aligns text |
vbMsgBoxRtlReading |
1048576 |
On Hebrew and Arabic systems, specifies that text should appear from right to left |
vbMsgBoxSetForeground |
65536 |
Makes the message box the foreground window |
Finally, the value returned by the MsgBox function can be compared with the following constants to determine which button was selected. Note that there is no need for a vbHelp constant, since selecting the Help button, if it is displayed, keeps the message box open but opens a help window to display context-sensitive help information.
Constant |
Value |
Description |
---|---|---|
vbAbort |
3 |
The Abort button |
vbCancel |
2 |
The Cancel button |
vbIgnore |
5 |
The Ignore button |
vbNo |
7 |
The No button |
vbOK |
1 |
The OK button |
vbRetry |
4 |
The Retry button |
vbYes |
6 |
The Yes button |