In Microsoft Office Access 2007, you can define a macro to execute just about any task you would otherwise initiate with the keyboard or the mouse. The unique power of macros in Office Access 2007 is their ability to automate responses to many types of events without forcing you to learn a programming language. The event might be a change in the data, the opening or closing of a form or a report, or even a change of focus from one control to another. Within a macro, you can include multiple actions and define condition checking so that different actions are performed depending on the values in your forms or reports.
Macros are particularly useful for building small, personal applications or for prototyping larger ones. As you’ll learn in Chapter 19, “Understanding Visual Basic Fundamentals,” you probably should use Microsoft Visual Basic for complex applications or for applications that will be shared by several users over a network. However, even if you think you’re ready to jump right into Visual Basic, you should study all the macro actions first. You’ll find that you’ll use nearly all of the available macro actions in Visual Basic, so learning macros is an excellent introduction to programming in Access in general.
The examples in this chapter are based on the Wedding List Macro (WeddingMC.accdb) sample database on the companion CD included with this book. The results you see from the samples in this chapter might not exactly match what you see in this book if you have changed the sample data in the files. Also, all the screen images in this chapter were taken on a Microsoft Windows Vista system with the display theme set to Blue. Your results might look different if you are using a different operating system or a different theme.
In this chapter, you will
Learn about the various types of actions you can define in macros
Tour the macro design facility and learn how to build both a simple macro and a macro with multiple defined actions
Learn how to manage the many macros you need for a form or a report by creating a macro group
See how to add conditional statements to a macro to control the actions Access performs
Learn about the new macro features in Access 2007 including embedded macros, error trapping in macros, temporary variables, and macro actions that are not trusted.
Learn how to reference other form and report objects in macros
Understand some of the actions automated with macros in the Wedding List Macro sample database
In Article 6, “Macro Actions,” on the companion CD, you’ll find summaries of the macro actions and of the events that can trigger a macro. You might find that article useful as a quick reference when you’re designing macros for your applications.