Previous page Previous     TOC Contents     Next pageNext

Writing macros in MS Access


When you want to control the flow of activities in the application there are several ways you can go. We'll look at a couple of them.

First, if you don't want to use the Menu Manager discussed in the previous lesson, you can create your own menu using a simple form, as in the example below.

If you only have a form with buttons, nothing much will happen. You have to tell the application what to do when a button is clicked. That's what macros are for.

It's important to save the macro and name it. Give it the same name as the form it's on. That will simplify your life later. If you use macros you'll probably end-up with dozens in the application. Trust me: if you use names like macro1 and macro2 and so on, you'll tear your hair out later in trying to find what each one does. So, name the macro the same as the form it's on and name the actions inside the macro the same as the buttons.

Macros can also be used to open a form from another form.

For example, if you have to change the customer's address while the customer is renting a movie, you don't do the change in the Invoice form. You call the Customers form from the Invoice form. The trick is to make sure that the Customers form that opens is the one for the customer who is on the invoice.

We could create a macro for that.

However, it's more easily done by using the Wizard. Make sure the Wizard is activated in the Toolbox (the magic wand) and it will be called automatically when you create the button.

Finally, you should add navigation buttons to all forms.

You may have noticed that the navigation bar at the bottom of every form, although it is functional, it is small and hard to work. Adding navigation buttons makes it easier for the user.

Every form should have the standard buttons: First, Previous, Next, Last, New record, Close form