Create macros in Access
A macro is a list of actions Access runs in order: open a form, run a query, show a message. Without a line of code you automate recurring steps, for example behind a button.
In short: in the Macro Designer you pick an action under “Add New Action” and fill in its arguments. OpenForm with a Where Condition filters as it opens, SetWarnings turns off the prompts for action queries, If branches, SetTempVar remembers a value.
Before you start: forms and reports from level 5, most recently the level 5 project.
Try it now
Add the actions as in the Macro Designer. Run shows what the macro does: which form opens with how many records, which messages appear, what changes in the tables.
Task The macro should open the form frmCustomers and show only the customers from the USA.
Customers 25 rows, 10 columns
| CustomerID | Company | FirstName | LastName | City | PostalCode | Country | CustomerSince | Regular | Discount |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Noah | Evans | Leeds | LS1 1UR | UK | 28 Feb 2023 | ☑ | 0.1 | |
| 2 | Shaw & Partners | Noah | Davies | Glasgow | G1 1XQ | UK | 5 Feb 2024 | ☐ | 0.03 |
| 3 | Northlight Inc | Sophia | Hall | Denver | 80202 | USA | 30 Jun 2024 | ☑ | 0 |
| 4 | Olivia | Evans | Bristol | BS1 4DJ | UK | 29 Jun 2022 | ☑ | 0 | |
| 5 | Olivia | Smith | London | EC1A 1BB | UK | 23 Sep 2025 | ☑ | 0 | |
| 6 | Northlight Inc | Mia | Evans | Manchester | M1 1AE | UK | 1 Feb 2025 | ☐ | 0.1 |
| 7 | Bauer Ltd | Ava | Wilson | UK | 14 Oct 2024 | ☐ | 0.05 | ||
| 8 | Lucas | Taylor | Glasgow | G1 1XQ | UK | 2 Jul 2023 | ☐ | 0 | |
| 9 | Jack | Clark | Seattle | 98101 | USA | 7 Nov 2022 | ☐ | 0.1 | |
| 10 | Northlight Inc | Henry | Taylor | Denver | 80202 | USA | 3 Nov 2022 | ☑ | 0.1 |
| 11 | Northlight Inc | Oliver | Johnson | Bristol | BS1 4DJ | UK | 6 Mar 2024 | ☐ | 0 |
| 12 | Henry | Taylor | Chicago | 60601 | USA | 24 Dec 2023 | ☐ | 0 | |
| 13 | Northlight Inc | Noah | Taylor | London | EC1A 1BB | UK | 12 Oct 2022 | ☐ | 0 |
| 14 | Summit Consulting | Mia | Smith | Austin | 78701 | USA | 6 Feb 2022 | ☑ | 0 |
| 15 | Mia | Clark | Austin | 78701 | USA | 9 Mar 2022 | ☑ | 0.05 | |
| 16 | Chloe | Hall | Seattle | 98101 | USA | 4 May 2022 | ☐ | 0.03 | |
| 17 | Market Street Clinic | Sophia | Johnson | Boston | 02108 | USA | 4 Jun 2023 | ☑ | 0 |
| 18 | Roth Legal | Mia | Wright | Manchester | M1 1AE | UK | 23 Sep 2022 | ☑ | 0.05 |
| 19 | Northlight Inc | Grace | Wright | UK | 16 Dec 2023 | ☐ | 0.03 | ||
| 20 | Northlight Inc | Olivia | Brown | Boston | 02108 | USA | 19 Jun 2023 | ☐ | 0.03 |
| 21 | Liam | Brown | Boston | 02108 | USA | 23 Jun 2025 | ☐ | 0.03 | |
| 22 | Bauer Ltd | James | Johnson | Manchester | M1 1AE | UK | 5 Jun 2025 | ☐ | 0.05 |
| 23 | Noah | Wilson | Austin | 78701 | USA | 23 May 2022 | ☐ | 0 | |
| 24 | Market Street Clinic | James | Smith | Bristol | BS1 4DJ | UK | 16 Jan 2022 | ☐ | 0.1 |
| 25 | Northlight Inc | Sophia | Hall | Denver | 80202 | USA | 4 Aug 2025 | ☑ | 0 |
The main actions
| Action | Arguments | does |
|---|---|---|
| OpenForm | Form Name, View, Filter Name, Where Condition, Data Mode, Window Mode | opens a form, filtered by the condition |
| OpenReport | Report Name, View, Filter Name, Where Condition, Window Mode | opens a report |
| OpenQuery | Query Name, View, Data Mode | shows a select query or runs an action query |
| MessageBox | Message, Beep, Type, Title | shows a message |
| SetTempVar | Name, Expression | stores a value in a TempVar |
| RemoveTempVar | Name | removes the TempVar |
| SetWarnings | Warnings On | turns prompts off or on |
| RunSQL | SQL Statement, Use Transaction | runs an action query as SQL |
| StopMacro | none | ends the macro |
Access offers SetWarnings and RunSQL only after you turn on Show All Actions on the Macro Design tab; in the macro they carry a warning icon.
Action queries without prompts
When a macro opens an update query, Access asks twice: “You are about to run an update query that will modify data in your table.” and then “You are about to update 5 row(s).” With SetWarnings (Warnings On: No) before it, neither prompt appears. Access turns warnings back on by itself when the macro ends; error messages always appear.
Task The saved update query qDiscountPlus raises the discount of regular customers. The macro should run it without Access asking for confirmation and then show the message “Discounts raised”.
Customers 25 rows, 10 columns
| CustomerID | Company | FirstName | LastName | City | PostalCode | Country | CustomerSince | Regular | Discount |
|---|---|---|---|---|---|---|---|---|---|
| 1 | Noah | Evans | Leeds | LS1 1UR | UK | 28 Feb 2023 | ☑ | 0.1 | |
| 2 | Shaw & Partners | Noah | Davies | Glasgow | G1 1XQ | UK | 5 Feb 2024 | ☐ | 0.03 |
| 3 | Northlight Inc | Sophia | Hall | Denver | 80202 | USA | 30 Jun 2024 | ☑ | 0 |
| 4 | Olivia | Evans | Bristol | BS1 4DJ | UK | 29 Jun 2022 | ☑ | 0 | |
| 5 | Olivia | Smith | London | EC1A 1BB | UK | 23 Sep 2025 | ☑ | 0 | |
| 6 | Northlight Inc | Mia | Evans | Manchester | M1 1AE | UK | 1 Feb 2025 | ☐ | 0.1 |
| 7 | Bauer Ltd | Ava | Wilson | UK | 14 Oct 2024 | ☐ | 0.05 | ||
| 8 | Lucas | Taylor | Glasgow | G1 1XQ | UK | 2 Jul 2023 | ☐ | 0 | |
| 9 | Jack | Clark | Seattle | 98101 | USA | 7 Nov 2022 | ☐ | 0.1 | |
| 10 | Northlight Inc | Henry | Taylor | Denver | 80202 | USA | 3 Nov 2022 | ☑ | 0.1 |
| 11 | Northlight Inc | Oliver | Johnson | Bristol | BS1 4DJ | UK | 6 Mar 2024 | ☐ | 0 |
| 12 | Henry | Taylor | Chicago | 60601 | USA | 24 Dec 2023 | ☐ | 0 | |
| 13 | Northlight Inc | Noah | Taylor | London | EC1A 1BB | UK | 12 Oct 2022 | ☐ | 0 |
| 14 | Summit Consulting | Mia | Smith | Austin | 78701 | USA | 6 Feb 2022 | ☑ | 0 |
| 15 | Mia | Clark | Austin | 78701 | USA | 9 Mar 2022 | ☑ | 0.05 | |
| 16 | Chloe | Hall | Seattle | 98101 | USA | 4 May 2022 | ☐ | 0.03 | |
| 17 | Market Street Clinic | Sophia | Johnson | Boston | 02108 | USA | 4 Jun 2023 | ☑ | 0 |
| 18 | Roth Legal | Mia | Wright | Manchester | M1 1AE | UK | 23 Sep 2022 | ☑ | 0.05 |
| 19 | Northlight Inc | Grace | Wright | UK | 16 Dec 2023 | ☐ | 0.03 | ||
| 20 | Northlight Inc | Olivia | Brown | Boston | 02108 | USA | 19 Jun 2023 | ☐ | 0.03 |
| 21 | Liam | Brown | Boston | 02108 | USA | 23 Jun 2025 | ☐ | 0.03 | |
| 22 | Bauer Ltd | James | Johnson | Manchester | M1 1AE | UK | 5 Jun 2025 | ☐ | 0.05 |
| 23 | Noah | Wilson | Austin | 78701 | USA | 23 May 2022 | ☐ | 0 | |
| 24 | Market Street Clinic | James | Smith | Bristol | BS1 4DJ | UK | 16 Jan 2022 | ☐ | 0.1 |
| 25 | Northlight Inc | Sophia | Hall | Denver | 80202 | USA | 4 Aug 2025 | ☑ | 0 |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
The first exercise in this lesson is free.
If blocks and TempVars
An If block runs its actions only when its condition is true; Else If and Else extend it, End If closes it. A TempVar keeps a value for the whole session. You read it in any expression with [TempVars]![Name], including the Where Condition of OpenForm.
Task The macro counts the open orders (no ShippedDate) in the TempVar Open. If there are any, it shows “Open orders: ” with the number, otherwise “All orders shipped”.
Orders 120 rows, 6 columns
| OrderID | CustomerID | OrderDate | ShippedDate | Freight | PaymentMethod |
|---|---|---|---|---|---|
| 1 | 16 | 30 Apr 2025 | 3 May 2025 | 4.90 | Invoice |
| 2 | 23 | 18 May 2025 | 26 May 2025 | 4.90 | PayPal |
| 3 | 19 | 16 Jul 2026 | 4.90 | Direct debit | |
| 4 | 11 | 31 Mar 2025 | 1 Apr 2025 | 0.00 | Invoice |
| 5 | 6 | 7 Dec 2025 | 9 Dec 2025 | 9.90 | PayPal |
| 6 | 18 | 19 May 2026 | 26 May 2026 | 6.90 | Direct debit |
| 7 | 7 | 15 Jun 2026 | 16 Jun 2026 | 4.90 | Credit card |
| 8 | 20 | 18 Mar 2025 | 19 Mar 2025 | 0.00 | PayPal |
| 9 | 10 | 29 Oct 2025 | 3 Nov 2025 | 0.00 | Direct debit |
| 10 | 7 | 21 Nov 2026 | 4.90 | Invoice | |
| 11 | 1 | 2 May 2025 | 10 May 2025 | 9.90 | Direct debit |
| 12 | 10 | 7 Aug 2025 | 9 Aug 2025 | 0.00 | Invoice |
| 13 | 3 | 17 Sep 2026 | 24 Sep 2026 | 9.90 | PayPal |
| 14 | 16 | 29 Jan 2026 | 1 Feb 2026 | 6.90 | Invoice |
| 15 | 4 | 13 Jun 2025 | 21 Jun 2025 | 4.90 | PayPal |
| 16 | 12 | 3 Nov 2025 | 12 Nov 2025 | 4.90 | Invoice |
| 17 | 9 | 5 May 2026 | 8 May 2026 | 9.90 | PayPal |
| 18 | 9 | 26 Sep 2025 | 2 Oct 2025 | 4.90 | PayPal |
| 19 | 14 | 8 Mar 2026 | 10 Mar 2026 | 0.00 | Credit card |
| 20 | 1 | 2 Apr 2026 | 6.90 | PayPal | |
| 21 | 18 | 17 Nov 2026 | 4.90 | PayPal | |
| 22 | 11 | 27 Jul 2026 | 4 Aug 2026 | 4.90 | PayPal |
| 23 | 12 | 23 Jun 2026 | 28 Jun 2026 | 4.90 | Credit card |
| 24 | 10 | 12 Jan 2026 | 16 Jan 2026 | 0.00 | Direct debit |
| 25 | 1 | 30 Mar 2026 | 31 Mar 2026 | 4.90 | Credit card |
| 26 | 3 | 3 Mar 2025 | 7 Mar 2025 | 4.90 | Invoice |
| 27 | 24 | 9 Mar 2025 | 11 Mar 2025 | 4.90 | PayPal |
| 28 | 1 | 22 Sep 2025 | 28 Sep 2025 | 4.90 | PayPal |
| 29 | 1 | 18 Feb 2025 | 22 Feb 2025 | 4.90 | Invoice |
| 30 | 19 | 13 Oct 2025 | 18 Oct 2025 | 4.90 | PayPal |
| 31 | 10 | 19 Sep 2025 | 25 Sep 2025 | 6.90 | PayPal |
| 32 | 6 | 19 Jun 2026 | 24 Jun 2026 | 4.90 | Credit card |
| 33 | 20 | 16 Jun 2026 | 22 Jun 2026 | 9.90 | Credit card |
| 34 | 13 | 23 May 2026 | 27 May 2026 | 9.90 | Direct debit |
| 35 | 16 | 24 May 2026 | 2 Jun 2026 | 4.90 | PayPal |
| 36 | 14 | 9 Nov 2026 | 14 Nov 2026 | 4.90 | PayPal |
| 37 | 3 | 11 Mar 2026 | 18 Mar 2026 | 9.90 | PayPal |
| 38 | 22 | 2 Jan 2025 | 10 Jan 2025 | 0.00 | Invoice |
| 39 | 12 | 21 Oct 2025 | 27 Oct 2025 | 0.00 | Invoice |
| 40 | 20 | 4 Nov 2026 | 5 Nov 2026 | 9.90 | PayPal |
| 41 | 17 | 29 Mar 2026 | 30 Mar 2026 | 4.90 | PayPal |
| 42 | 13 | 6 Jan 2026 | 8 Jan 2026 | 0.00 | Invoice |
| 43 | 3 | 24 Feb 2026 | 26 Feb 2026 | 4.90 | PayPal |
| 44 | 7 | 21 Sep 2026 | 28 Sep 2026 | 4.90 | Invoice |
| 45 | 2 | 17 Apr 2025 | 23 Apr 2025 | 0.00 | Direct debit |
| 46 | 7 | 27 Apr 2026 | 28 Apr 2026 | 4.90 | Invoice |
| 47 | 3 | 16 Nov 2026 | 6.90 | Direct debit | |
| 48 | 1 | 26 Jun 2026 | 27 Jun 2026 | 4.90 | Credit card |
| 49 | 24 | 29 Apr 2026 | 30 Apr 2026 | 4.90 | PayPal |
| 50 | 1 | 23 Mar 2025 | 28 Mar 2025 | 4.90 | Direct debit |
| 51 | 10 | 28 Jan 2026 | 31 Jan 2026 | 0.00 | PayPal |
| 52 | 22 | 9 May 2026 | 15 May 2026 | 4.90 | Direct debit |
| 53 | 10 | 29 Dec 2025 | 7 Jan 2026 | 0.00 | Credit card |
| 54 | 4 | 17 Oct 2026 | 18 Oct 2026 | 9.90 | Credit card |
| 55 | 24 | 30 Aug 2025 | 31 Aug 2025 | 6.90 | Credit card |
| 56 | 6 | 29 Jan 2026 | 2 Feb 2026 | 4.90 | PayPal |
| 57 | 18 | 10 Dec 2025 | 13 Dec 2025 | 6.90 | Direct debit |
| 58 | 13 | 4 Mar 2025 | 9 Mar 2025 | 9.90 | Invoice |
| 59 | 11 | 29 Nov 2025 | 7 Dec 2025 | 6.90 | Invoice |
| 60 | 9 | 30 Oct 2025 | 4 Nov 2025 | 4.90 | Invoice |
| 61 | 10 | 17 Mar 2026 | 19 Mar 2026 | 4.90 | PayPal |
| 62 | 9 | 14 Jul 2025 | 21 Jul 2025 | 4.90 | PayPal |
| 63 | 8 | 24 May 2025 | 2 Jun 2025 | 0.00 | Invoice |
| 64 | 4 | 29 Sep 2026 | 5 Oct 2026 | 4.90 | Invoice |
| 65 | 10 | 22 Jan 2026 | 27 Jan 2026 | 9.90 | Invoice |
| 66 | 9 | 27 Mar 2026 | 28 Mar 2026 | 9.90 | Credit card |
| 67 | 14 | 11 Sep 2026 | 18 Sep 2026 | 4.90 | PayPal |
| 68 | 4 | 9 Jun 2026 | 16 Jun 2026 | 0.00 | Invoice |
| 69 | 17 | 10 Jan 2026 | 17 Jan 2026 | 9.90 | Credit card |
| 70 | 21 | 1 Apr 2026 | 2 Apr 2026 | 4.90 | Credit card |
| 71 | 15 | 19 Mar 2025 | 21 Mar 2025 | 4.90 | Credit card |
| 72 | 20 | 4 Mar 2025 | 6 Mar 2025 | 4.90 | Invoice |
| 73 | 10 | 24 May 2025 | 9.90 | PayPal | |
| 74 | 8 | 3 Jan 2025 | 4 Jan 2025 | 9.90 | Invoice |
| 75 | 23 | 30 Oct 2025 | 6 Nov 2025 | 9.90 | Direct debit |
| 76 | 22 | 30 Aug 2025 | 3 Sep 2025 | 6.90 | Invoice |
| 77 | 2 | 18 Nov 2025 | 23 Nov 2025 | 6.90 | PayPal |
| 78 | 3 | 22 Dec 2025 | 26 Dec 2025 | 4.90 | Invoice |
| 79 | 21 | 26 May 2026 | 6.90 | Invoice | |
| 80 | 24 | 23 Feb 2026 | 27 Feb 2026 | 4.90 | Direct debit |
| 81 | 2 | 5 Jun 2026 | 6.90 | PayPal | |
| 82 | 11 | 14 Aug 2026 | 6.90 | Invoice | |
| 83 | 21 | 10 May 2026 | 18 May 2026 | 9.90 | Credit card |
| 84 | 13 | 12 Feb 2025 | 19 Feb 2025 | 4.90 | Credit card |
| 85 | 2 | 22 Jan 2026 | 30 Jan 2026 | 4.90 | PayPal |
| 86 | 2 | 31 Oct 2025 | 4 Nov 2025 | 9.90 | Credit card |
| 87 | 6 | 9 Mar 2025 | 17 Mar 2025 | 9.90 | Credit card |
| 88 | 3 | 5 Feb 2025 | 14 Feb 2025 | 9.90 | Direct debit |
| 89 | 17 | 26 Jan 2025 | 29 Jan 2025 | 6.90 | PayPal |
| 90 | 11 | 25 Sep 2026 | 4.90 | Direct debit | |
| 91 | 22 | 23 May 2025 | 1 Jun 2025 | 4.90 | Credit card |
| 92 | 20 | 29 Jan 2025 | 2 Feb 2025 | 0.00 | PayPal |
| 93 | 8 | 16 Jul 2026 | 18 Jul 2026 | 6.90 | Invoice |
| 94 | 2 | 7 Aug 2025 | 10 Aug 2025 | 0.00 | Invoice |
| 95 | 22 | 6 Jan 2025 | 8 Jan 2025 | 6.90 | Credit card |
| 96 | 15 | 15 Dec 2025 | 24 Dec 2025 | 4.90 | Invoice |
| 97 | 6 | 23 Sep 2025 | 30 Sep 2025 | 6.90 | Invoice |
| 98 | 10 | 10 Sep 2025 | 16 Sep 2025 | 0.00 | Invoice |
| 99 | 14 | 10 Jan 2026 | 13 Jan 2026 | 9.90 | Credit card |
| 100 | 16 | 20 Nov 2025 | 24 Nov 2025 | 0.00 | Credit card |
| 101 | 18 | 26 Jul 2026 | 27 Jul 2026 | 4.90 | Credit card |
| 102 | 2 | 15 May 2025 | 9.90 | Invoice | |
| 103 | 4 | 8 Feb 2025 | 15 Feb 2025 | 6.90 | Credit card |
| 104 | 7 | 16 Sep 2026 | 17 Sep 2026 | 4.90 | Invoice |
| 105 | 7 | 26 Jan 2025 | 31 Jan 2025 | 4.90 | Direct debit |
| 106 | 23 | 2 Aug 2026 | 3 Aug 2026 | 6.90 | Direct debit |
| 107 | 13 | 22 Jan 2026 | 26 Jan 2026 | 9.90 | Credit card |
| 108 | 4 | 6 Oct 2025 | 14 Oct 2025 | 4.90 | Direct debit |
| 109 | 10 | 6 Nov 2025 | 9 Nov 2025 | 4.90 | Direct debit |
| 110 | 9 | 17 Oct 2026 | 18 Oct 2026 | 9.90 | PayPal |
| 111 | 23 | 24 May 2026 | 25 May 2026 | 6.90 | Direct debit |
| 112 | 2 | 31 Aug 2025 | 1 Sep 2025 | 9.90 | Direct debit |
| 113 | 20 | 25 Jul 2026 | 28 Jul 2026 | 0.00 | Direct debit |
| 114 | 6 | 24 Nov 2025 | 27 Nov 2025 | 9.90 | Credit card |
| 115 | 8 | 27 Nov 2025 | 30 Nov 2025 | 6.90 | Credit card |
| 116 | 1 | 18 Mar 2025 | 25 Mar 2025 | 0.00 | Direct debit |
| 117 | 9 | 16 Mar 2025 | 19 Mar 2025 | 6.90 | Credit card |
| 118 | 4 | 10 Jul 2026 | 15 Jul 2026 | 0.00 | Invoice |
| 119 | 14 | 23 Jun 2025 | 28 Jun 2025 | 4.90 | Direct debit |
| 120 | 2 | 21 Sep 2026 | 27 Sep 2026 | 4.90 | Direct debit |
This exercise is part of Premium.
Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.
See Premium Already Premium? Log in
The first exercise in this lesson is free.
In real Access
- Create, Macro opens the Macro Designer. Pick the action under Add New Action; on the right, the Action Catalog lists every action by group, with If, Comment, Group and Submacro under Program Flow.
- Fill in the arguments right below the action. Conditions and expressions use the same functions as queries, such as
DCount("*","Orders","ShippedDate Is Null"). - Save, then Run. If something goes wrong, Single Step on the same tab helps.
- To run the macro from a button, choose it in the Property Sheet, Event tab, On Click.
Common mistakes
Text in the condition without quotes
[Country]=USA looks for a field called USA. Text goes in quotes: [Country]="USA".
SetWarnings is missing from the list
It is one of the actions Access offers only after Show All Actions.
Unknown name in an expression
If an expression contains a name that does not exist, the macro stops: “Microsoft Access cannot find the name '…' you entered in the expression.” Check the spelling of fields and TempVars.
FAQ
Macro or VBA?
Macros are enough for flows made of standard actions: open, filter, run queries, show messages. For loops over records, calculations and detailed error handling, VBA is the right tool. Access converts macros on request: Convert Macros to Visual Basic on the Macro Design tab.
How does a value survive between two macros?
With a TempVar. It lasts until you remove it with RemoveTempVar or close Access.