Use a UI macro for buttons and form events, a data macro for table changes, and VBA only when you need code. That is the fastest safe rule for Microsoft Access macros. Choosing the wrong type can break forms, block actions, or fire changes in the wrong place. This guide shows where to find each macro type, how to create and run it, and how to fix trust-center blocks and common errors.
Microsoft Access macros automate repeated tasks in forms, reports, controls, and tables by running steps when an event happens. They can be standalone objects or embedded in the host object. UI macros handle interface actions such as opening a form or report. Data macros attach to tables and run from table events.
What Access macros do
UI macros versus data macros
UI macros are the right fit for actions tied to a form, report, or control. A button can run a macro through its OnClick event. Data macros belong to tables and use table events like Before Change and After Insert. That split matters because a form event cannot replace a table event, and a table event cannot handle a button click.
Standalone macros versus embedded macros
Standalone macros can be separate objects in the database. Embedded macros are part of the object they belong to. Embedded macros are not visible in the Navigation Pane, and they typically travel with the form, report, or control when that object is copied to another database.
What you'll need
Have these ready before you start.
- An Access database file that contains the form, report, control, or table you want to automate.
- Access to the Macro Builder on the Create tab.
- Macro permissions for the current Microsoft 365 app.
- A clear target event, such as OnClick, Before Update, or After Insert.
How do you enable macros in Access?
Enable macros in the Trust Center for the Access app you are using. These settings are per Microsoft 365 app, so changing Word or Excel does not change Access. If a policy blocks the setting, you may need admin help; that is a Group Policy issue, not a normal Access setting.
- Open Trust Center. Go to File > Options > Trust Center > Trust Center Settings. Then open Macro Settings. Choose Disable all macros with notification if you want to review files before you trust them, or Enable all macros only for controlled, trusted databases.
- Trust the file location. If the database came from email or the web, Windows may mark it as blocked. Move it to a trusted folder or use the file properties to unblock it, then reopen Access. This is often the fastest fix when a macro exists but never starts.
- Confirm the app setting. Reopen the database in Access and look for the security bar or notification state. If Access still blocks the file after the setting change, check whether a policy is enforcing the macro setting. Microsoft Access has no Trust access to the VBA project model object option, so VBA trust is handled differently from macro trust.
Safety note: do not enable macros in an unknown file just to make it open. If the source is not trusted, leave macro security in place and inspect the file in a separate location or copy.
How do you create a macro in Access?
Create macros in the Macro Builder. For UI macros, the Create tab contains Macro. For data macros, create the table event from the table design area. Use the builder to pick actions from a list instead of typing code.
- Start the builder. Go to Create > Macro for a UI macro. For a data macro, open the table, then choose the table event you want, such as Before Change or After Insert.
- Add the first action. In the Macro Builder, choose an action from the list. For a form button, a common first action is OpenForm. For a table rule, choose the table-level action that matches the event.
- Enter exact arguments. Use real object names and field names. Example: SetTempVar with Name = CustomerID and Expression = [Forms]![frmOrder]![CustomerID]. Then add OpenForm with Form Name = frmCustomerDetails, Where Condition = [CustomerID]=[TempVars]![CustomerID], and Window Mode = Dialog.
Picture a common first-timer setup: a form called frmOrder has a button that should open frmCustomerDetails for the selected customer. If the button does nothing, the issue is often a missing event assignment, not the action itself.
How do you run an existing macro?
Run a macro from the Navigation Pane, from a control event, or from within the Macro Builder. The path you choose depends on whether the macro is standalone or embedded. If the macro does not appear in the Navigation Pane, it may be embedded inside a form, report, or control.
- Run the standalone macro. In the Navigation Pane, double-click the macro object. That is the quickest check for a standalone macro.
- Run it from a form event. Open the form in Design View, select the control, and set the event property such as On Click. Choose Macro Builder or the macro name so Access knows what to run.
- Test it in single-step mode. Use Single Step to watch each action one at a time. That helps you see the action that fails instead of guessing. For error paths, add OnError and ClearMacroError near the relevant actions so the macro can branch cleanly after a failure.
Temporary variables help move values between objects. Create them with SetTempVar, then read them later from another form, report, or VBA procedure. Remove one with RemoveTempVar or clear everything with RemoveAllTempVars when the workflow ends.
Macro decision table
This table maps common Access tasks to the right macro type, where to build it, how to run it, and the most likely failure point.
| Task | Macro type | Location | Trigger | Troubleshooting note |
|---|---|---|---|---|
| Open a customer detail form from a button | UI macro | Form control event or embedded macro | OnClick | Check that the button’s OnClick property points to the macro. |
| Copy the selected order ID to another form | UI macro | Create tab > Macro | Button click or form event | Verify the TempVars name matches exactly. |
| Enforce a table rule before saving a record | Data macro | Table design | Before Change | Use a table event, not a form event. |
| Stamp a date after a new row is added | Data macro | Table design | After Insert | Make sure the field is writable and the event actually fires. |
| Open a report from a navigation button | UI macro | Form or report embedded macro | OnClick | Confirm the report name and view mode are correct. |
| Run a macro when a text box changes | UI macro | Control property sheet | After Update | Use the control’s event property, not the form’s general properties. |
| Store a filter value for later use | UI macro | Standalone or embedded | Button click | Check TempVars cleanup after the report closes. |
| Block an invalid record before save | Data macro | Table event macro | Before Change | Unsupported actions may fail in a table macro. |
| Reuse a macro inside several forms | UI macro | Standalone object | Called from multiple events | Standalone macros are easier to reuse than embedded ones. |
| Move a record value into a dialog form | UI macro | Form button or event macro | OnClick | Wrong event scope is the common failure point. |
Common mistakes
The most common failure points are macro security disabled, the macro attached to the wrong event, an unsupported action for that macro type, and a blocked file trust state. Start with the event property and the Trust Center before you rewrite the macro.
- Check the security state first. Go to File > Options > Trust Center > Trust Center Settings > Macro Settings. If Access is set to disable macros without notification, the macro can exist and still never run.
- Verify the event property. Open the host object in Design View, then inspect the relevant property sheet field such as On Click or Before Change. If the macro is attached to the wrong event, move it to the correct one.
- Match the macro type. Use a UI macro for forms, reports, and controls. Use a data macro for table events. If a macro action is unsupported in that scope, replace it with a supported action or move the logic to VBA.
Suppose a button should open a report, but nothing happens after click. The fastest check is the button’s OnClick property. If that property is blank or points to the wrong macro, the action is fine and the attachment is not.
Frequently asked questions
What are macros in Access?
Macros are automation steps that run inside Access to handle repeated tasks in forms, reports, controls, and tables. They can be standalone objects or embedded in the host object. Use them for opening objects, validating input, or reacting to events without writing VBA code.
How do you access macros in Access?
Open the Navigation Pane to run standalone macros, or open the host object in Design View and inspect its event properties. For new macros, go to Create > Macro. Embedded macros stay inside the form, report, or control and will not appear as separate objects.
How do you run a macro in Access?
Double-click a standalone macro in the Navigation Pane, or trigger an embedded macro through its event property, such as On Click. For a quick test, open the macro in the Macro Builder and use Single Step to run the actions one by one.
How do you enable macros in Microsoft Access?
Open File > Options > Trust Center > Trust Center Settings > Macro Settings, then choose either Disable all macros with notification or Enable all macros. The setting applies to Access, not to other Microsoft 365 apps, and a policy can block the change.
How do you allow macros in Access?
Allow the file only after you trust its source and location. If Windows marked the file as blocked, clear that state and reopen it. Then confirm the Access macro setting in the Trust Center. If the database still fails, check whether the macro is attached to the right event.