Adding Tabs and Controls to the Office Fluent Ribbon in Access 2007

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Summary: Learn how to customize the ribbon for an Access 2007 database application.

Office Visual How To

**Applies to:**2007 Microsoft Office system, Microsoft Office Access 2007

David Hale, Microsoft Corporation

Joel Krist, Akona Systems

March 2007

Overview

Microsoft Office Access 2007 lets you customize the ribbon in your application. The ribbon provides a new user model for exposing commands, and it provides easier, more discoverable navigation. You can create a custom ribbon for an Office Access 2007 database by using only ribbon extensibility markup XML and macros.

Code It

This video demonstrates the four steps to customize the ribbon for a database application:

  1. Create XML markup in the editor of your choice.

  2. Load XML into the database.

  3. Set database, form, and report properties to show customizations.

  4. Use macros or VBA to handle simple actions, such as button clicks.

Creating XML Markup

The following XML samples demonstrate the basic steps to create the XML markup that will display the custom ribbon buttons in an Access database. To see how to add these to your database, watch the video.

The simple XML below sets the startFromScratch attribute to True, which hides the default ribbon.

Next, extend the XML to add a new tab to hold your custom buttons.

Finally, add the buttons by adding the emphasized code show below.

Let's look now at the details of the XML.

  • The imageMso attribute refers to a ribbon image name that is pulled from the 2007 Office System Icon Gallery.

  • The onAction attribute invokes a macro named Ribbon.MarketingProjectsHome that creates a macro object named ribbon. This object contains an action called MarketingProjectsHome that calls the OpenForm action to open the Marketing Projects Home form.

Using VBA to Handle More Advanced Actions

You can do many powerful actions using macros, but you may need to use more advanced tasks by creating VBA functions. For example, you need to write code for the following scenarios:

  • Loading XML from a remote location.

  • Implementing a callback.

  • Loading custom images.

Loading Remote Code

This code creates a Recordset from any table that contains the word "Ribbons" in its name. Then it calls the LoadCustomUI method to load the ribbons, to make them available to the database. And finally, it closes the Recordset and the reference to the DAO.Database object.

Implementing Callbacks

In the following example, the group element is declared with the label attribute. The label for this group is static, which means it is set when the group is created:

In practice, you may want to assign the label dynamically. In the following example, the group element is declared with the getLabel attribute. When this group is created, the ribbon calls the getLabel function to get the value for the label.

The following example shows the VBA function that is called when the ribbon evaluates the XML in the previous example.

Loading Custom Images

The following VBA examples show how to implement the getImage callback function to load images from an attachment field in the current database. This function uses a form to load images.

In this example, all the images for the application are stored in the same record.

In the previous function, the USysRibbonImages opens as read-only and in hidden mode. This indicates that it is not in the UI. The images are retrieved from the Images control. The image whose name corresponds to the imageId that is requested by the ribbon is returned.

In the following example, images for the application are stored in different records. If a record contains more than one image in the Images field, the first image is retrieved by default.

Read It

Access provides flexibility in customizing the ribbon UI. For example, you can store customization markup in a table, embedded in a Visual Basic for Applications (VBA) procedure, stored in another Access database, or linked to from a Microsoft Office Excel 2007 worksheet. You can also specify a custom UI for the application as a whole or for specific forms and reports.

You create XML to change the ribbon UI. You can create customization files in any text editor. All applications that include the ribbon use the same extensibility model, so you can reuse the same ribbon extensibility XML with a minimum of adjustments. For example, you can reuse the custom XML you create for the 2007 Microsoft Office release programs, such as Microsoft Office Word, Microsoft Office Excel, Microsoft Office PowerPoint, or Access, and for Microsoft Office Outlook 2007.

For more information about ribbon architecture and the specification of the XML markup, see Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3).

See It Screen shot of video title

Watch the Video

Length: 00:07:22| Size: 7.4 MB | Type: WMV file

Explore It