MessageBox Macro Action

In Access databases you can use the MessageBox macro action to display a message box containing a warning or an informational message. For example, you can use the MessageBox macro action with validation macros. When a control or record fails a validation condition in the macro, a message box can display an error message and provide instructions about the kind of data that should be entered.

Note: Some of the content in this topic may not be applicable to some languages.

Note: Beginning in Access 2010, the MsgBox macro action was renamed to MessageBox.

Setting for Access desktop databases

In Access desktop databases the MessageBox macro action has the following arguments.

Action argument

Description

Message

The text in the message box. Enter the message text in the Message argument box. You can type up to 255 characters or enter an expression (preceded by an equal sign).

Beep

Specifies whether your computer or device's speaker sounds a beep tone when the message displays. Select Yes (sound the beep tone) or No (don't sound the beep tone). The default is Yes.

Type

The type of message box. Each type has a different icon. Select None, Critical, Warning?, Warning!, or Information. The default is None.

Title

The text displayed in the message box title bar. For example, you can have the title bar display "Customer ID Validation". If you leave this argument blank, "Microsoft Access" is displayed.

Setting for Access web apps

In Access web apps the MessageBox macro action only has one argument.

Action argument

Description

Message

The text in the message box. Enter the message text in the Message argument box. You can type up to 255 characters or enter an expression (preceded by an equal sign).

Remarks

In Access desktop databases you can use the MessageBox macro action to create a formatted error message similar to built-in error messages displayed by Access. The MessageBox macro action permits you to supply a message in three sections for the Message argument. You separate the sections with the "@" character.

The following example displays a formatted message box with a sectioned message. The first section of text in the message is displayed as a bold heading. The second section is displayed as plain text beneath that heading. The third section is displayed as plain text beneath the second section, with a blank line between them.

Type the following string in the Message argument:

Wrong button!@This button doesn't work.@Try another.

Note: This special formatting technique can't be used in Access web apps.

You can't run the MessageBox action in a Visual Basic for Applications (VBA) module. Use the MsgBox function instead.

Examples

Message box scenarios

The following examples show different types of scenarios for using the MessageBox macro action.

Action

Argument

Comment

MessageBox

Message: Move to the supplier record whose products you want to see, then click the Review Products button again.

Beep: No

Type: None

Title: Select a Supplier

In this example, if there is no current supplier on the Suppliers form, display a message. Access doesn't display any icon with the message.

MessageBox

Message: Please enter a supplier name before attempting to save the record.

Beep: Yes

Type: Warning!

Title: Supplier name missing

In this example, if there is no supplier name provided for the record when the user attempts to save the record, display a message with an audible sound. Access displays an exclamation point icon with this message.

MessageBox

Message: ="The supplier " & [Forms]![Suppliers]![Supplier Name] & " is already in the database."

Beep: Yes

Type: Critical

Title: Duplicate supplier

In this desktop database example, the user entered a duplicate supplier name into the Suppliers form. In the Message argument, the expression concatenates custom message text and displays the supplier name the user typed into the Supplier Name control on the Suppliers form. Access displays a message with an audible sound and a critical icon with this message.



Was this information helpful?

How can we improve it?

How can we improve it?

To protect your privacy, please do not include contact information in your feedback. Review our privacy policy.

Thank you for your feedback!