Office 2010 - Access

Lesson 67: Using Macros

67/76 Lessons 

Macro (2)

We continue to add a field to our “Macro”.

If you have closed the “Macro”, right-click it in the “Navigation Pane” (1) and select “Design View” from the pop-up menu.
When the “Macro” is open, click the downward-pointing arrow of the “Add New Action” (2) box.
In the drop-down list that appears, choose “GoToControl”.
A field in the form is in fact, a control, as we have seen in a previous lesson.

les67_image001_en

Type the name of the control in brackets as the “Control Name” (1), and click the “Run” (2) button.
To save the “Macro”, you must answer “Yes” to the message.

les67_image002_en
As you see in the image below, the form opens and the cursor is in the second field, namely the “Lastname” field.

les67_image003_en

Add Macro to a button

Now that we have created a “Macro”, we need a way to perform this action, by clicking a button or some event.
The first thing I’m going to show is, to add this to a button.

As an example, I have a report with a list of all teachers in the school.
It would be useful here if a button is available to open the form which we have just made a “Macro”.
The first thing we do is, open the report in “Design View”.
Click the “Controls” (1) and select “Button”.
Then draw the button in the report (2). The place does not matter.
Open the “Properties Window” and choose “Format” tab . In the “Caption” you give the button an appropriate name (3).
Then choose the “Event” tab in the “Properties window” (4) and click the downward pointing arrow next to the “OnClick” (5) box.
It opens and lists all custom “Macros”.
I have only one, so the list is not very large.
Select the “Macro” in the list and then test your report in “Report View”.

les67_image004_en

Add Macro to an event

In this example, I’ll show you how to run a “Macro” when a certain event happens. For example, when we open the report that we saw in the above section .
For this, I will open a window that displays a message.

The first thing we do is create a “Macro”.

Select this “Create” tab in the “Ribbon” and click the “Macro” button.
Click the downward pointing arrow to add a “Macro” and choose “message box” in the pop-up menu.

les67_image005_en
In the upper section of the “Macro”, you type the message you want to display.
In the second box, determine whether it gives a beep or not when it appears.
And the third and fourth section seem obvious to me .
Close the “Macro” and save it when you’re prompted.

les67_image006_en
Now to execute this “Macro” when the “teachers” form opens, open the “teachers” form in “Design View” and click on the “Properties Window”.

By clicking the downward pointing arrow next to the ‘On Open’ action, choose the newly created “Macro”.
Close the form and save it.

les67_image007_en
When you’re in the “Teachers list” report, click the “Add” button and you will see that you get this message window .
If you click the OK button in this window, it will then open the “teachers” form.

les67_image008_en

Awesome!
You've completed Lesson 67
START NEXT LESSON