Code Samples for Businesses, Schools & Developers

First Published 26 Nov 2022


This page provides a convenient reference list of message box constants and their equivalent values.
You can use either values or constants in your code (or use them interchangeably)

Message boxes in Office applications such as Access can have:
- up to 4 buttons including an optional Help button
- one of 4 optional icons
- a specified default button
- left or right aligned text
- text reading right to left for Hebrew/Arabic languages

For example:

ExampleMsgBoxes


These message box styles are all defined using the following MsgBox arguments

MsgBox Arguments


Constant Value Description
vbOKOnly 0 OK button only (default)
vbOKCancel 1 OK and Cancel buttons
vbAbortRetryIgnore 2 Abort, Retry, and Ignore buttons
vbYesNoCancel 3 Yes, No, and Cancel buttons
vbYesNo 4 Yes and No buttons
vbRetryCancel 5 Retry and Cancel buttons
vbCritical 16 Critical message
vbQuestion 32 Warning query
vbExclamation 48 Warning message
vbInformation 64 Information message
vbDefaultButton1 0 First button is default (default setting)
vbDefaultButton2 256 Second button is default
vbDefaultButton3 512 Third button is default
vbDefaultButton4 768 Fourth button is default
vbApplicationModal 0 Application modal message box (default)
vbSystemModal 4096 System modal message box
vbMsgBoxHelpButton 16384 Adds Help button to the message box
VbMsgBoxSetForeground 65536 Specifies the message box window as the foreground window
vbMsgBoxRight 524288 Text is right aligned
vbMsgBoxRtlReading 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems



Constants / values can also be combined. For example, these all create the same result

MsgBox "Are you sure you want to do this?", vbQuestion+vbYesNo+vbDefaultButton2, "Delete this record?"


MsgBox "Are you sure you want to do this?", 32+4+vbDefaultButton2, "Delete this record?"


MsgBox "Are you sure you want to do this?", 32+4+256, "Delete this record?"


MsgBox "Are you sure you want to do this?", 292,"Delete this record?"



CombineValues


MsgBox Return Values

Similarly the value returned by the user clicking on a message box button is evaluated using one of the following:


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



Once again, these can be referenced in code using either the constant or the value.

For example, either of the following code examples can be used to detect whether the user pressed Yes or No in this message box:

CheckReturnValues

If MsgBox("8 new records were added to the table tblCustomerOrders" & vbCrLf & vbCrLf & _
      "Do you want to view these records now?", vbQuestion + vbYesNo + vbDefaultButton2, "View imported records?") = vbYes Then
            cmdViewTable_Click
Else
      Exit Sub
End If


If MsgBox("8 new records were added to the table tblCustomerOrders" & vbCrLf & vbCrLf & _
      "Do you want to view these records now?", 32 + 4 + 256, "View imported records?") = 6 Then
            cmdViewTable_Click
Else
      Exit Sub
End If





NOTE:
The same constants / values apply if you are using non-standard message boxes. Click the links for more details of each:

a)   formatted message box

FormattedMsgBox
b)   WizHook message box

WizHookMsgBox
c)   Task dialog message

TaskDialogMessage


Please use the contact form below to let me know whether you found this article useful or if you have any questions.



Colin Riddington           Mendip Data Systems                 Last Updated 26 Nov 2022



Return to Code Samples Page Return to Top