Create a Macro to Display a Message

Previous Topic

Previous Page
Next Topic

Next Page

When you find yourself repeating the same tasks, such as searching for products that you need to reorder, create a macro to display a message that an item is “out of stock” if there are no units in stock and no units on order.

Properties button

Save button

In the database window, on the Forms tab, select Products. Click Design to open the Products form in form design view. Click the Units In Stock text box, and then click the Properties button. On the Event tab, click After Update. To open the macro window and create the macro, use the procedures shown in the following illustration. When you’re done, click the Save button. Microsoft Access runs the macro whenever you change the number of units in stock to zero when the number of units on order is also zero.

Want to modify a macro?   In the database window, on the Macros tab, click the macro you want to modify, and then click Design.

What other actions can a macro carry out?   A macro can set the value in a field, control, or property (the SetValue action), carry out a Microsoft Access menu command (the RunCommand action), or simulate typing on the keyboard (the SendKeys action), among other actions. To learn more about a macro action, in the macro window, select the action in the Action column and then press F1.

Want a macro to carry out a series of actions in response to a single event?   Select each action you want to carry out in a separate row of the macro window. Microsoft Access carries out the actions row by row.

More About Macros and Events

How are events named?   Events are named after the user actions that cause them. For example, when you change the units in stock to zero in the Products form, the macro that displays the “out of stock” message runs in response to an “AfterUpdate” event.

Create macros that respond to other events   You can create other macros that tell Microsoft Access what to do when a user opens a form (an Open event), moves from one record to another (a Current event), or clicks a specific button (a Click event).

Office Assistant button

Want to know more?   Look up Getting Results - Automate Microsoft Access in Help.