Learn Access Now!      Chapter 17      Next Section in Chapter 18      Chapter 19

Chapter 18: Creating and Using Macros

(This is section 1 of 6 in this chapter)

As you work more with Access, you will discover many ways you can tailor your Access environment to your needs. One of the ways Access lets you simplify tasks is with macros. In short, a macro is a recording of the steps you perform to accomplish a specific task.

For example, to print a table, you select the File menu Print option and then choose OK within the Print dialog box. Using an Access macro, you record these steps. Later, you can play back your macro and Access will automatically perform the steps for you. As you will learn, you can write macros that perform simple or complex tasks.

By the time you finish this chapter, you will understand the following key concepts:

What Are Macros?

You have probably heard the term "macro" before. In general, a macro is nothing but a series of commands an application program executes. Macros help you automate tasks within a program such as Access. Macros let you program your software without requiring you to learn or even understand the basics of writing a program. For example, both Word and Excel include macro languages you can use to automate a series of commands. When you record and then execute a macro, the macro typically mimics the steps a user would take when manually using a program.

Access also has a macro language you can use. Access has 53 macro actions; you can pass values (called arguments) to a macro action to control the operations the action performs. (An action is an instruction that directs Access to perform a specific act, such as selecting an option from a menu.) Table 18-1 lists the different macro actions available.

Action Purpose
AddMenu Adds a drop-down menu to a menu bar. Used in forms and reports.
ApplyFilter Applies a filter to a table.
Beep Sounds the PC speaker.
CancelEvent Cancels the event that ran the current macro.
Close Closes a window.
CopyObject Copies a database object.
DeleteObject Deletes a database object.
Echo Controls whether a macro updates the screen.
FindNext Finds the next record meeting the search criteria specified in a FindRecord action.
FindRecord Finds a record that meets your criteria.
GoToControl Changes focus to a particular control.
GoToPage Changes focus to a specified page in a form.
GoToRecord Jumps to a specified record.
Hourglass Controls whether the mouse pointer is displayed as an hourglass.
Maximize Same as clicking your mouse on a window's maximize button.
Minimize Same as clicking your mouse on a window's minimize button.
MoveSize Moves or resizes a window.
MsgBox Displays a message box.
OpenDataAccessPage Opens a data access page.
OpenDiagram Opens a diagram showing the layout of the database.
OpenForm Opens a form.
OpenModule Opens a Visual Basic for Applications module.
OpenQuery Opens an existing query.
OpenReport Opens an existing report.
OpenStoredProcedure Opens and runs a stored SQL procedure.
OpenTable Opens an existing table.
OpenView Opens a database view.
OutputTo Exports data in either Excel or text format.
PrintOut Prints a database object.
Quit Quits Access.
Rename Renames a database object.
RepaintObject Redraws a database object on the screen.
Requery Updates the information in a control.
Restore Same as clicking your mouse on a window's restore button.
RunApp Runs a Windows or DOS program.
RunCode Executes a Visual Basic for Applications function.
RunCommand Executes an Access command, such as those on the menu or toolbar.
RunMacro Executes another macro.
RunSQL Executes an SQL statement.
Save Saves an Access object.
SelectObject Selects a named object.
SendKeys Sends information to the keyboard buffer, as if it had been typed.
SendObject Sends a database object using E-mail.
SetMenuItem Changes the state of a menu item.
SetValue Specifies the contents of a field, control, or property.
SetWarnings Controls the display of system messages.
ShowAllRecords Removes the effects of a filter.
ShowToolbar Displays a particular toolbar.
StopAllMacros Stops execution of all macros.
StopMacro Stops the current macro.
TransferDatabase Imports or exports information.
TransferSpreadsheet Imports or exports to a spreadsheet program.
TransferText Imports or exports to a text file.

Table 18-1 The Access macro actions.

Note: To see detailed help on any particular macro action, search for the action name in the Access online Help system.

Learn Access Now!      Chapter 17      Next Section in Chapter 18      Chapter 19