Share this page:

MS Access: MsgBox Arguments

This MSAccess tutorial explains how to use MsgBox arguments with syntax and examples.

The MsgBox function is one of the most commonly used functions within Access. It is a method of interacting with the user during a session. Therefore, you must accurately select the buttons for your MsgBox. Below is a table that lists all of your MsgBox options.

Applies To

  • Access 2013, Access 2010, Access 2007, Access 2003, Access XP, Access 2000

Arguments

The arguments for MsgBox are as follows:

Constant Value Description
vbOkOnly 0 Displays 1 button - OK (default value)
vbOkCancel 1 Displays 2 buttons - OK and Cancel
vbAbortRetryIgnore 2 Displays 3 buttons - Abort, Retry, Ignore
vbYesNoCancel 3 Displays 3 buttons - Yes, No, and Cancel
vbYesNo 4 Displays 2 buttons - Yes and No
vbRetryCancel 5 Displays 2 buttons - Retry and Cancel
vbCritical 16 Displays a critical message
vbQuestion 32 Displays a question
vbExclamation 48 Displays a warning message
vbInformation 64 Displays an information message
vbDefaultButton1 0 Displays 1 button - OK which is the default
vbDefaultButton2 256 Second button is default
vbDefaultButton3 512 Third button is default
vbDefaultButton4 768 Fourth button is default
vbApplicationModal 0 Displays 1 button - OK. Modal message box for the application.
vbSystemModal 4096 Displays 1 button - OK. Modal message box for the system.
vbMsgBoxHelpButton 16384 Displays 2 buttons - OK and Help.
vbMsgBoxSetForeground 65536 Displays 1 button - OK. Message box window becomes the foreground window.
VbMsgBoxRight 524288 Displays 1 button - OK. The text message is right aligned.
VbMsgBoxRtlReading 1048576 Displays 1 button - OK. Used for Hebrew and Arabic systems.

Example

Here is an example of how you can use a MsgBox.

Dim LResponse As Integer

LResponse = MsgBox("Do you wish to continue?", vbYesNo, "Continue")

If LResponse = vbYes Then
   {...statements...}
Else
   {...statements...}
End If

You've declared a variable called LResponse that stores the result from the MsgBox function. If the user clicks on the Yes button, LResponse will contain the vbYes value and if the user clicks on the No button, LResponse will contain the vbNo value.

See a list of the MsgBox return values (ie: vbYes, vbNo, etc).