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
CustomerIDCompanyFirstNameLastNameCityPostalCodeCountryCustomerSinceRegularDiscount
1NoahEvansLeedsLS1 1URUK28 Feb 2023☑0.1
2Shaw & PartnersNoahDaviesGlasgowG1 1XQUK5 Feb 2024☐0.03
3Northlight IncSophiaHallDenver80202USA30 Jun 2024☑0
4OliviaEvansBristolBS1 4DJUK29 Jun 2022☑0
5OliviaSmithLondonEC1A 1BBUK23 Sep 2025☑0
6Northlight IncMiaEvansManchesterM1 1AEUK1 Feb 2025☐0.1
7Bauer LtdAvaWilsonUK14 Oct 2024☐0.05
8LucasTaylorGlasgowG1 1XQUK2 Jul 2023☐0
9JackClarkSeattle98101USA7 Nov 2022☐0.1
10Northlight IncHenryTaylorDenver80202USA3 Nov 2022☑0.1
11Northlight IncOliverJohnsonBristolBS1 4DJUK6 Mar 2024☐0
12HenryTaylorChicago60601USA24 Dec 2023☐0
13Northlight IncNoahTaylorLondonEC1A 1BBUK12 Oct 2022☐0
14Summit ConsultingMiaSmithAustin78701USA6 Feb 2022☑0
15MiaClarkAustin78701USA9 Mar 2022☑0.05
16ChloeHallSeattle98101USA4 May 2022☐0.03
17Market Street ClinicSophiaJohnsonBoston02108USA4 Jun 2023☑0
18Roth LegalMiaWrightManchesterM1 1AEUK23 Sep 2022☑0.05
19Northlight IncGraceWrightUK16 Dec 2023☐0.03
20Northlight IncOliviaBrownBoston02108USA19 Jun 2023☐0.03
21LiamBrownBoston02108USA23 Jun 2025☐0.03
22Bauer LtdJamesJohnsonManchesterM1 1AEUK5 Jun 2025☐0.05
23NoahWilsonAustin78701USA23 May 2022☐0
24Market Street ClinicJamesSmithBristolBS1 4DJUK16 Jan 2022☐0.1
25Northlight IncSophiaHallDenver80202USA4 Aug 2025☑0

The main actions

ActionArgumentsdoes
OpenFormForm Name, View, Filter Name, Where Condition, Data Mode, Window Modeopens a form, filtered by the condition
OpenReportReport Name, View, Filter Name, Where Condition, Window Modeopens a report
OpenQueryQuery Name, View, Data Modeshows a select query or runs an action query
MessageBoxMessage, Beep, Type, Titleshows a message
SetTempVarName, Expressionstores a value in a TempVar
RemoveTempVarNameremoves the TempVar
SetWarningsWarnings Onturns prompts off or on
RunSQLSQL Statement, Use Transactionruns an action query as SQL
StopMacrononeends 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
CustomerIDCompanyFirstNameLastNameCityPostalCodeCountryCustomerSinceRegularDiscount
1NoahEvansLeedsLS1 1URUK28 Feb 2023☑0.1
2Shaw & PartnersNoahDaviesGlasgowG1 1XQUK5 Feb 2024☐0.03
3Northlight IncSophiaHallDenver80202USA30 Jun 2024☑0
4OliviaEvansBristolBS1 4DJUK29 Jun 2022☑0
5OliviaSmithLondonEC1A 1BBUK23 Sep 2025☑0
6Northlight IncMiaEvansManchesterM1 1AEUK1 Feb 2025☐0.1
7Bauer LtdAvaWilsonUK14 Oct 2024☐0.05
8LucasTaylorGlasgowG1 1XQUK2 Jul 2023☐0
9JackClarkSeattle98101USA7 Nov 2022☐0.1
10Northlight IncHenryTaylorDenver80202USA3 Nov 2022☑0.1
11Northlight IncOliverJohnsonBristolBS1 4DJUK6 Mar 2024☐0
12HenryTaylorChicago60601USA24 Dec 2023☐0
13Northlight IncNoahTaylorLondonEC1A 1BBUK12 Oct 2022☐0
14Summit ConsultingMiaSmithAustin78701USA6 Feb 2022☑0
15MiaClarkAustin78701USA9 Mar 2022☑0.05
16ChloeHallSeattle98101USA4 May 2022☐0.03
17Market Street ClinicSophiaJohnsonBoston02108USA4 Jun 2023☑0
18Roth LegalMiaWrightManchesterM1 1AEUK23 Sep 2022☑0.05
19Northlight IncGraceWrightUK16 Dec 2023☐0.03
20Northlight IncOliviaBrownBoston02108USA19 Jun 2023☐0.03
21LiamBrownBoston02108USA23 Jun 2025☐0.03
22Bauer LtdJamesJohnsonManchesterM1 1AEUK5 Jun 2025☐0.05
23NoahWilsonAustin78701USA23 May 2022☐0
24Market Street ClinicJamesSmithBristolBS1 4DJUK16 Jan 2022☐0.1
25Northlight IncSophiaHallDenver80202USA4 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
OrderIDCustomerIDOrderDateShippedDateFreightPaymentMethod
11630 Apr 20253 May 20254.90Invoice
22318 May 202526 May 20254.90PayPal
31916 Jul 20264.90Direct debit
41131 Mar 20251 Apr 20250.00Invoice
567 Dec 20259 Dec 20259.90PayPal
61819 May 202626 May 20266.90Direct debit
7715 Jun 202616 Jun 20264.90Credit card
82018 Mar 202519 Mar 20250.00PayPal
91029 Oct 20253 Nov 20250.00Direct debit
10721 Nov 20264.90Invoice
1112 May 202510 May 20259.90Direct debit
12107 Aug 20259 Aug 20250.00Invoice
13317 Sep 202624 Sep 20269.90PayPal
141629 Jan 20261 Feb 20266.90Invoice
15413 Jun 202521 Jun 20254.90PayPal
16123 Nov 202512 Nov 20254.90Invoice
1795 May 20268 May 20269.90PayPal
18926 Sep 20252 Oct 20254.90PayPal
19148 Mar 202610 Mar 20260.00Credit card
2012 Apr 20266.90PayPal
211817 Nov 20264.90PayPal
221127 Jul 20264 Aug 20264.90PayPal
231223 Jun 202628 Jun 20264.90Credit card
241012 Jan 202616 Jan 20260.00Direct debit
25130 Mar 202631 Mar 20264.90Credit card
2633 Mar 20257 Mar 20254.90Invoice
27249 Mar 202511 Mar 20254.90PayPal
28122 Sep 202528 Sep 20254.90PayPal
29118 Feb 202522 Feb 20254.90Invoice
301913 Oct 202518 Oct 20254.90PayPal
311019 Sep 202525 Sep 20256.90PayPal
32619 Jun 202624 Jun 20264.90Credit card
332016 Jun 202622 Jun 20269.90Credit card
341323 May 202627 May 20269.90Direct debit
351624 May 20262 Jun 20264.90PayPal
36149 Nov 202614 Nov 20264.90PayPal
37311 Mar 202618 Mar 20269.90PayPal
38222 Jan 202510 Jan 20250.00Invoice
391221 Oct 202527 Oct 20250.00Invoice
40204 Nov 20265 Nov 20269.90PayPal
411729 Mar 202630 Mar 20264.90PayPal
42136 Jan 20268 Jan 20260.00Invoice
43324 Feb 202626 Feb 20264.90PayPal
44721 Sep 202628 Sep 20264.90Invoice
45217 Apr 202523 Apr 20250.00Direct debit
46727 Apr 202628 Apr 20264.90Invoice
47316 Nov 20266.90Direct debit
48126 Jun 202627 Jun 20264.90Credit card
492429 Apr 202630 Apr 20264.90PayPal
50123 Mar 202528 Mar 20254.90Direct debit
511028 Jan 202631 Jan 20260.00PayPal
52229 May 202615 May 20264.90Direct debit
531029 Dec 20257 Jan 20260.00Credit card
54417 Oct 202618 Oct 20269.90Credit card
552430 Aug 202531 Aug 20256.90Credit card
56629 Jan 20262 Feb 20264.90PayPal
571810 Dec 202513 Dec 20256.90Direct debit
58134 Mar 20259 Mar 20259.90Invoice
591129 Nov 20257 Dec 20256.90Invoice
60930 Oct 20254 Nov 20254.90Invoice
611017 Mar 202619 Mar 20264.90PayPal
62914 Jul 202521 Jul 20254.90PayPal
63824 May 20252 Jun 20250.00Invoice
64429 Sep 20265 Oct 20264.90Invoice
651022 Jan 202627 Jan 20269.90Invoice
66927 Mar 202628 Mar 20269.90Credit card
671411 Sep 202618 Sep 20264.90PayPal
6849 Jun 202616 Jun 20260.00Invoice
691710 Jan 202617 Jan 20269.90Credit card
70211 Apr 20262 Apr 20264.90Credit card
711519 Mar 202521 Mar 20254.90Credit card
72204 Mar 20256 Mar 20254.90Invoice
731024 May 20259.90PayPal
7483 Jan 20254 Jan 20259.90Invoice
752330 Oct 20256 Nov 20259.90Direct debit
762230 Aug 20253 Sep 20256.90Invoice
77218 Nov 202523 Nov 20256.90PayPal
78322 Dec 202526 Dec 20254.90Invoice
792126 May 20266.90Invoice
802423 Feb 202627 Feb 20264.90Direct debit
8125 Jun 20266.90PayPal
821114 Aug 20266.90Invoice
832110 May 202618 May 20269.90Credit card
841312 Feb 202519 Feb 20254.90Credit card
85222 Jan 202630 Jan 20264.90PayPal
86231 Oct 20254 Nov 20259.90Credit card
8769 Mar 202517 Mar 20259.90Credit card
8835 Feb 202514 Feb 20259.90Direct debit
891726 Jan 202529 Jan 20256.90PayPal
901125 Sep 20264.90Direct debit
912223 May 20251 Jun 20254.90Credit card
922029 Jan 20252 Feb 20250.00PayPal
93816 Jul 202618 Jul 20266.90Invoice
9427 Aug 202510 Aug 20250.00Invoice
95226 Jan 20258 Jan 20256.90Credit card
961515 Dec 202524 Dec 20254.90Invoice
97623 Sep 202530 Sep 20256.90Invoice
981010 Sep 202516 Sep 20250.00Invoice
991410 Jan 202613 Jan 20269.90Credit card
1001620 Nov 202524 Nov 20250.00Credit card
1011826 Jul 202627 Jul 20264.90Credit card
102215 May 20259.90Invoice
10348 Feb 202515 Feb 20256.90Credit card
104716 Sep 202617 Sep 20264.90Invoice
105726 Jan 202531 Jan 20254.90Direct debit
106232 Aug 20263 Aug 20266.90Direct debit
1071322 Jan 202626 Jan 20269.90Credit card
10846 Oct 202514 Oct 20254.90Direct debit
109106 Nov 20259 Nov 20254.90Direct debit
110917 Oct 202618 Oct 20269.90PayPal
1112324 May 202625 May 20266.90Direct debit
112231 Aug 20251 Sep 20259.90Direct debit
1132025 Jul 202628 Jul 20260.00Direct debit
114624 Nov 202527 Nov 20259.90Credit card
115827 Nov 202530 Nov 20256.90Credit card
116118 Mar 202525 Mar 20250.00Direct debit
117916 Mar 202519 Mar 20256.90Credit card
118410 Jul 202615 Jul 20260.00Invoice
1191423 Jun 202528 Jun 20254.90Direct debit
120221 Sep 202627 Sep 20264.90Direct 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

  1. 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.
  2. Fill in the arguments right below the action. Conditions and expressions use the same functions as queries, such as DCount("*","Orders","ShippedDate Is Null").
  3. Save, then Run. If something goes wrong, Single Step on the same tab helps.
  4. 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.

Learn next: VBA in Access

DoCmd, event procedures and Me.

VBA in Access

Write to us

Choose language

Select your preferred language