Home Privacy Policy Feedback Link to us Site Map

Access: MsgBox Return Values


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.

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

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.

To see a list of the buttons that a MsgBox can display, click here.