Adding Tabs and Groups

Controls such as buttons, drop-downs, and checkboxes are organized into tabs and groups in the Ribbon. Tabs appear at the top of the Ribbon and contain groups. You can define your own tabs and groups, or you can incorporate controls from existing tabs and groups. Tabs are defined using the tab element and groups are defined using the group element.

Here's an example. Say you want to add a tab with one group to the existing Ribbon. The following XML adds a new tab called My Tab at the end of the existing tab set. Start with the customUl node and the ribbon node that you saw in the previous section:

<customUI xmlns=""> <ribbon startFromScratch="false">

To define tabs, you first add a tabs node under the ribbon node to say that you are defining a tab set:

Next, add the tab using the tab node as follows:

<tab id="tabMyTab" label="My Tab">

Add the group below the tab:

<group id="grpMyGroup" label="My Group"></group>

Now, finish the XML by adding the end nodes:

</tab> </tabs> </ribbon> </customUI>

Notice that the tab and group nodes include attributes named id and label. All controls that you add to your Ribbon including tabs and groups must have an ID attribute, which is a string that is unique throughout the Ribbon and cannot contain spaces. Add this XML to the RibbonXml field of the USysRibbons table. Assign the XML the name My First Ribbon in the RibbonName field and then set the Ribbon Name property in the Access Options dialog box to the same name: My First Ribbon. When you've completed these steps, you should have something that looks like the Ribbon shown in Figure 12-5.

Figure 12-5

Congratulations! You've just written your first custom ribbon!

For the remainder of this section, the customUl and ribbon nodes are omitted in the XML. Except where noted, each of the following examples should include these nodes.

If you are using an IDE that provides IntelliSense, you may have noticed an attribute in the tab node called insertBeforeMso or insertAfterMso. You can use these attributes to set the position of a tab relative to an existing tab in Access. For example, here's the XML that will move the My Tab tab to the beginning of the Ribbon instead of the end:

<tab id="tabMyTab" insertBeforeMso="TabHomeAccess" label="My Tab">

<group id="grpMyGroup" label="My Group"/> </tab> </tabs>

The first tab always receives the focus after a tab is switched. Imagine that your My Tab appears before the Home tab, and you open a form in Design view. Forms and reports in Design view display a contextual tab that enables you to work with the design surfaces. When you close the form, focus is given back to the first tab — in this case, the custom My Tab. You'll see more about contextual tabs shortly.

Any attribute that ends with Mso refers to items provided by Office. For example, imageMso refers to images that are included in Office. This attribute is discussed later in the chapter.

It is also possible to add a new group to an existing tab by specifying the idMso attribute. You can use this attribute to refer to tabs, groups, and even controls that are provided by Office. (More on re-using groups and controls later.)

The following XML adds the group called My Group after the Clipboard group in the Home tab:

<tab idMso="TabHomeAccess">

<group id="grpMyGroup" label="My Group" insertAfterMso="GroupClipboard"/> </tab> </tabs>

Figure 12-6 shows the result.

Figure 12-6

Fun, huh? Wait, it gets better!

You can also choose to include an existing group in another tab. For example, the Clipboard group contains the familiar controls for Cut, Copy, and Paste, which are pretty useful, so say you want to include that group in your tab. The following XML adds the Clipboard group and two custom groups to My Tab:


<tab id="

'tabMyTab" label="My Tab">


id="grpMyGroup1" label="First Group"/>




id="grpMyGroup2" label="Second Group"/>



The result of this Ribbon is shown in Figure 12-7.

The result of this Ribbon is shown in Figure 12-7.

Figure 12-7

Now let's take a look at contextual tabs.

Was this article helpful?

0 0

Post a comment