USysRibbons
System TableUSysRibbons
TableNew to Access 2007, the ribbon is the strip across the top of the application window that contains groups of commands. The ribbon in Microsoft Office Access 2007 replaces both menus and toolbars found in earlier versions of Access. As a developer, you might not want the default ribbon to appear in your applications. You may want to hide existing functionality or to add new functionality. You need to understand how to customize the ribbon to be able to accomplish these tasks. Unfortunately, there is no user interface to modify the ribbon. You have to pull up your sleeves and use Extensible Markup Language (XML) to customize the ribbon. This chapter shows you all the tips and tricks that you need to know to add custom ribbons to your overall application and to your forms and reports.
Using ribbon customization techniques, you can hide existing tabs, add new tabs, add new command groups, and add new commands to a command group. You accomplish all these tasks by using XML. Although there are several places that you can store the XML used to customize the ribbon, the easiest method is to store the XML in a system table in the current database. The steps are as follows:
USysRibbons
.Several steps are involved in creating and applying a custom ribbon. The following is an overview of the steps involved:
USysRibbons
table.USysRibbons
table.The sections that follow cover each of these steps in detail.
The first step that you should take when creating a new ribbon or modifying the existing ribbon is to show system tables in your database. You accomplish this task by using the Navigation Options. Here’s how:
Figure 23.1. Using the Navigation Options dialog box, you can opt to show system tables.
Figure 23.2. After you opt to show system tables, they appear in the Navigation Pane.
The second step when customizing the ribbon is to enable the display of add-in user interface error messages. Here’s the process:
Figure 23.3. Select Show Add-In User Interface Errors from the General group.
USysRibbons
TableThe next step is to create the USysRibbons
system table. Here are the steps involved:
AutoNumber
field called ID
that has a field size of Long Integer.Text
field called RibbonName
that has a field size of 255.Memo
field called RibbonXml
. The table design appears in Figure 23.4.
Figure 23.4. It is important that you design the custom table exactly the same as in the example.
ID
field as the Primary Key.USysRibbons
.USysRibbons
TableYou are now ready to add data to the USysRibbons
table. Here are the steps involved:
USysRibbons
table in Datasheet view.USysRibbons
table.Listing 23.1. Writing the XML Necessary to Customize the Ribbon
The XML first tells Access to display the default tabs. It then designates that the Create tab will be hidden. Next, the XML creates a ribbon tab named My New Tab. It then adds a command group called My Custom Group to the tab. Finally, it adds the Copy command to the group.
Now that you have created the ribbon code, you are ready to apply the ribbon. You can apply the ribbon to the entire database or to a specific form or report. The sections that follow explain each process in detail.
To apply the ribbon to the entire database, follow these steps:
Figure 23.5. You must use the Ribbon and Toolbar Options to select your ribbon.
Figure 23.6. You must close and reopen the database for the change to take effect.
Figure 23.7. The ribbon appears with all the custom features that you designated.
In the preceding example, you assigned a custom ribbon to a database. Now look at how to assign a custom ribbon to a form or report. Here are the steps involved:
Ribbon Name
property and open the drop-down to display the available ribbons (see Figure 23.8).
Figure 23.8. You must select the ribbon that you want to associate with the form.
Figure 23.9. The custom ribbon is associated with the designated form.
After you have determined that your custom ribbons are working properly, you can once again hide the system objects. To do this, follow these steps:
Sometimes you will want to restore the ribbon back to its default settings. The process differs depending on whether you have assigned the ribbon to the entire database or to a form or report. Let’s start with how to restore a ribbon customized for the entire application:
You will sometimes need to return the ribbon associated with a form or report back to the default ribbon. Here’s how:
Ribbon Name
property.Figure 23.10 shows the new tab further customized. Notice that it now contains two groups, and the first group contains two commands. Listing 23.2 shows in bold the XML modifications necessary to make these changes.
Listing 23.2. Adding Groups and Commands to the Ribbon
Figure 23.10. The new ribbon contains an additional group and control.
Notice that the example creates an additional control on the My New Group tab. It also adds a new group containing one control. Figure 23.10 illustrates the result of the changes.
You might be wondering where you can find the idMso
value associated with a command. The idMso
value determines which command Access associates with the button. Here are the steps involved:
Figure 23.11. Adding a ribbon to your Access 2007 application.
idMso
value you want to know. The idMso
value appears as a ToolTip.You may want to run a macro that you created directly from the ribbon. Listing 23.3 illustrates this simple process.
Listing 23.3. Executing a Macro from the Ribbon
The code in the example executes the macro named SayHello
. The button is named RunCustomMacro
, and its label is Say Hello
.
Practice adding a custom ribbon to one of your databases. Apply the ribbon to the entire database. Then create a second custom ribbon and apply that ribbon to a particular form or report. Finally, add a macro to the ribbon.
Because ribbons didn’t exist in earlier versions of Access, the process of creating them is different from any process in those earlier versions. In this chapter, you learned how to create a system table that contains the XML necessary to create or modify a ribbon. You also learned how to determine when the custom ribbon displays. You learned how to restore the ribbon to its default settings, and finally how to execute macros from the ribbon. All of these techniques are necessary when creating new ribbons or modifying existing ones.
18.226.180.161