totn Access

MS Access: MsgBox Return Values

This MSAccess tutorial explains how to use MsgBox 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.

Applies To

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

Return Values

The return values for MsgBox are as follows:

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

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 buttons that a MsgBox can display.