Tip:
Highlight text to annotate it
X
In Access 2010, macros play a more prominent role than in previous versions.
In particular, if you are creating a Web database,
you must use macros instead of Visual Basic for Applications (VBA) code
to accomplish programming tasks.
That's because VBA will not run in a browser.
UI macros, or User Interface macros,
are attached to events on forms and reports.
The term "UI macro" distinguishes them from data macros,
which are tied to events that occur in tables.
In this video, I’ll show you how to create a UI macro
that opens a detail form when you click an item in a list form.
This is a common navigation design in many database applications.
The list helps you find a record quickly,
while a detail form often provides a more readable format
for viewing a single record.
So, I’ll select the table, and then on the Create tab,
I’ll click Datasheet.
I’ll save it as ContactList, with an "frm" prefix, for form.
Now I’ll create the detail form. I select the Contacts table again,
and then on the Create tab, I click Form.
I’ll resize these columns a little bit to make them more compact.
And I’ll save this form as frmContactDetails, and then close it.
Now I’ll show you how to make the connection
between the list form and the detail form.
I’ll do this by attaching an embedded UI macro
to the ID field of the datasheet form.
I’ll start by making sure the Property Sheet is open.
If it isn’t, I can click Property Sheet on the Datasheet tab,
or press F4 to open it.
I want to make it so that whenever I click one of these IDs,
the detail form will open and display the corresponding record.
First I select the field by clicking its column header.
Then, on the Event tab of the Property Sheet,
I click in the On Click property box, and then I click the Build button.
There are a variety of ways to build this macro,
but at a minimum, I know I need the macro to open a form.
So, in the Action Catalog search box, I’ll type "open."
OpenForm is the action I want, so I’ll drag it into the macro pane.
Now all I have to do is fill in some arguments.
For the Form Name argument, I’ll select the detail form I just created.
The Where Condition is where I specify
which record I want to see on the detail form.
I want the detail form to display the record
that has the same ID that I clicked on the list form.
I’ll use standard Access syntax to specify the ID on the list form.
Notice how the new IntelliSense feature is helping me enter the identifiers.
I want to be able to edit the record on the detail form,
so I’ll choose Edit from the Data Mode list.
And I want the detail form to pop up over the list form like a dialog box,
so I’ll select Dialog from the Window Mode list.
Now I’m ready to test the macro.
I click Close, and then Yes to save the changes.
Here’s my new embedded macro in the Property Sheet.
I’ll close the Property Sheet.
And now, let’s say I want to view the details for the record with ID number 7.
I just click that ID, and my detail form opens to that record.
Let’s try it again with another record just to make sure.
I click ID number 5, and the detail form opens to that record.
Because I used a UI macro, if I publish this database to a SharePoint server,
the macro works in the browser just the same way as it does on the client.