Fix Access 2019 VBA Event Procedure Prompts for a Macro Name
Question details
The user needs to understand why a macro name dialog appears when trying to run VBA code created for a button's On Click event.

- Product
- Microsoft Access 2019
- Device & OS
- not provided
- Scenario
- Attempting to test or run VBA code written for a command button's On Click event from within the VBA Editor.
- Observed behavior
- Instead of executing the code, Microsoft Access opens a dialog asking for a macro name.
Ensure your Access database is saved, macro settings are enabled in the Trust Center, and your form is opened in Design View.
Test the Code in Form View (Do Not Use F5)
Run the event procedure from the actual form interface instead of the VBA Editor.
In Microsoft Access, button click events (e.g., Private Sub Command0_Click) are created as private procedures within a specific form or report class module. Because they are private and depend on the form's runtime context, you cannot run them by simply placing your cursor in the code and pressing F5 or clicking the Run button in the VBA Editor.
When you try to run a private procedure directly, the VBA Editor doesn't know how to trigger it, so it opens the Macro dialog asking you to specify a public macro to run instead.
Click the 'Save' icon in the VBA Editor toolbar or press 'Ctrl + S' to save your recent code changes.
Minimize or close the VBA Editor window to return to your main Microsoft Access workspace.
Right-click the form's tab at the top of the working area and select 'Form View' from the context menu.
Click the command button you just programmed. The VBA code will now execute properly using the correct form context.
Verify the On Click Property is Set to Event Procedure
Ensure the button's property is explicitly configured to run VBA code rather than looking for an embedded Access macro.
Looking for a Lightweight Office Suite with Excellent VBA Support?
While WPS Office does not include a direct database replacement for Microsoft Access, WPS Spreadsheet offers robust VBA and Macro capabilities for powerful data management. It provides a highly compatible environment for your Excel-based VBA projects without the heavy resource requirements of Microsoft Office.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package.
- 2. Install WPS Office: Run the installer and follow the quick on-screen instructions to set up the software.
- 3. Enable VBA Support: Open WPS Spreadsheet, navigate to the Developer tab, and seamlessly import or write your VBA macros.

Frequently Asked Questions
Why does pressing F5 in the VBA Editor ask for a macro name?
Pressing F5 in the VBA Editor attempts to run the current procedure. However, form event procedures (like button clicks) are marked as 'Private' and require the form's runtime context. Since the editor cannot provide this context directly, it asks you to select a 'Public' macro instead.
What is the difference between an Embedded Macro and an Event Procedure in Access?
An Embedded Macro uses Microsoft Access's visual Macro Builder tool to automate tasks without coding. An Event Procedure uses Microsoft Visual Basic for Applications (VBA) code, offering much more advanced logic, error handling, and flexibility.
Can I temporarily change a Private Sub to Public to test it with F5?
While changing 'Private Sub' to 'Public Sub' allows the VBA Editor to see it, running it via F5 is still not recommended. Event procedures often reference form controls (e.g., 'Me.TextBox1'). Running them outside of Form View will result in runtime errors because the 'Me' object is not instantiated.




