VBA & Macro Problems

How to Create a Yes or No Confirmation Message in an Access Macro

Phi Hung VoPhi Hung Vo Nov 4, 2026 868 views

Question details

The user needs to add a Yes/No confirmation prompt to an existing Access button macro so that the action only executes if 'Yes' is selected.

How to Create a Yes/No Confirmation Prompt in an Access Macro
Product
Microsoft Access
Device & OS
not provided
Scenario
Preventing accidental execution of a macro that updates a date control and disables a button by confirming the user's intent first.
Observed behavior
The macro currently runs immediately upon clicking the button. The goal state is to halt execution entirely if the user selects 'No' on a confirmation prompt.
Before you start

Ensure you have your Access database opened in Design View and locate the specific macro attached to the button's On Click event.

Solution 1Recommended

Add an If Action with the MsgBox Function

Use an If block to evaluate the user's response to a Yes/No message box before allowing the rest of the macro to execute.

To intercept a macro sequence, you can place an 'If' condition at the very beginning of the macro. By calling the MsgBox function with specific numeric parameters, you can trigger a dialog box with Yes and No buttons, and then halt the macro if the No button is clicked.

1
Open the Macro Builder

Right-click your form and select 'Design View'. Select the button, open the Property Sheet, go to the 'Event' tab, and click the ellipsis (...) next to the 'On Click' property to open the Macro Builder.

2
Insert the If Action

From the Action Catalog on the right, double-click the 'If' action to add it. Click the up arrow to move this If block to the very top of your macro sequence.

3
Configure the Condition

In the condition box of the If block, type: MsgBox("Do you want to proceed?", 36) = 7. The number 36 generates a Yes/No prompt with a question icon, and 7 represents the value returned when 'No' is clicked.

4
Stop the Macro

Inside the If block, add a 'StopMacro' action. This ensures that if the condition is met (the user clicked No), the macro stops completely. The rest of your existing actions will remain outside the If block and will only run if 'Yes' is selected.

Add an If Action with the MsgBox Function
Understanding MsgBox Values: In Microsoft Access macros, the number 36 is the sum of the vbYesNo button configuration (4) and the vbQuestion icon (32). The number 7 is the standard return value for vbNo.
Free Microsoft Office alternative

Looking for a Lightweight Alternative for Your Everyday Office Needs?

While WPS Office does not include a direct database management tool like Microsoft Access, it is an excellent, free alternative for your daily document, spreadsheet, and presentation tasks, offering high compatibility with Microsoft Office file formats.

  1. 1. Download and Install: Get WPS Office for free from the official website and install it on your preferred device.
  2. 2. Import Your Data: Export your Access tables to Excel format and open them directly in WPS Spreadsheets without losing your tabular data structure.
  3. 3. Utilize Advanced Formulas and Macros: Manage your datasets efficiently using the built-in VBA editor, pivot tables, and advanced data processing tools available in WPS Spreadsheets.
Fully compatible with Microsoft Office formats including .docx, .xlsx, and .pptx.Includes powerful Spreadsheet tools for complex data analysis and macro (VBA) support.Lightweight design that installs quickly and runs smoothly on PC, Mac, and mobile devices.Free to use with a familiar, tabbed interface for seamless migration from Microsoft Office.
microsoft office alternative - wps office

Frequently Asked Questions

Can I use a traditional VBA script instead of the Access Macro Builder?

Yes. You can convert the button's event to a Visual Basic Code Builder block and use standard VBA syntax. You would simply write: If MsgBox("Are you sure?", vbYesNo + vbQuestion, "Confirm") = vbNo Then Exit Sub.

What does the number 36 mean in the Access macro MsgBox function?

In the Macro Builder, 36 is a combined parameter value. It adds the numeric value for a Yes/No button layout (which is 4) and the value for a Question mark icon (which is 32) to generate the specific confirmation prompt layout.

Why does my macro still run and update the date after I click No?

This usually happens if the 'StopMacro' action is not placed correctly inside the If block, or if your condition checking for the 'No' response (value 7) contains a typo. Ensure the StopMacro action is indented directly under the If condition.