Creating the XML Code

Table 15.1 lists some of the most commonly used XML elements for customizing an Access 2007 Ribbon.

TABLE 15.1

XML Elements for Use in Customizing the Ribbon

Element Name Usage Comments customUI The top-level element for a custom Ribbon ribbon The Ribbon definition Set the startFromScratch attribute to

"true" to create a new, blank Ribbon. (The quotes are needed, a difference from VBA code with its True and False keywords.) If set to "false" or omitted, the customizations are applied to the standard Ribbon.


Creates or references a Ribbon tab


Creates or references a group on a tab


Unique name of a custom control


Name of a standard control


Text displayed on a control


A command button on a Ribbon

The onAction attribute specifies the name of a function to run when the button is clicked.


A drop-down list

Automatically limited to list selections.


A drop-down list that allows manual entries

Users can enter selections or select from the list.


The image to use for the control

Set with the name of a built-in Ribbon control (or a custom image you have created).


The size of the control

The choices are "normal" and "large".


The text to display in the pop-up that appears when your mouse hovers over a control


Whether the control is visible or not

The choices are "true" or "false".


Whether the control is enabled or not

The choices are "true" or "false".

Element names in XML use camel-casing notation; the first letter of the element name is lowercase, and other components have their first letter capitalized (giving the appearance of a camel's hump). Example: dropDown.

You can start by creating a table to hold the Ribbon XML code, or create the XML code first, as you prefer. If you have just one table of Ribbon code, the convention is to call it USysRibbons, with the USys prefix indicating that it is a user-created system table. The table has three fields, as described in Table 15.2.

TABLE 15.2

The USysRibbons Table

Field Name

Data Type




Unique ID field


Text, 255

Name of the custom Ribbon



The XML code with Ribbon settings

Viewing the USysRibbons Table he USysRibbons table is a system table, so you won't see it unless you turn on display of system tables by opening the Access Options screen from the Office menu:

Recent Documents

1 G:\Unzip\Test Ribbon.accdb

2 G:\Unzip\Extras 2007.accda

3 G;\Document5\,,.\Northwmd Plus,accdb

5 G:\Unzip\OId Extras.mda

6 G:\Unzip\Extras.mda

7 G:\Unzip\Extras.accda

8 G:\Documents\n.\Extras 2007.accda

9 GADocuments\,,.\Extras 2007.accdb

Close Database

Opening the Access Options screen.

continued continued

And then select the Current Database page and click the Navigation Options button:

Access options

Current Database

Datasheet Object Designer Proofing

Trust Center

U Options for the current database.

Application Options

Application Title: Northwind

Application Icon: j l~l Use as Form Display Foi

EZJ Display Status Bar Document Window Options a .Overlapping Windows © Tabbed Documents

SI Display Document Tabs H Use Access Special Keys CD □ Compact on Close

E Remove personal information from file properties on save E Use Windows-themed Controls on Forms IEI Enable Layout View for this database

|7] Enable design changes for tables in Datasheet view (for this database] ¡7] Check for truncated number fields Picture Property Storage Format j Preserve source image format (smaller file size) @ Convert all picture data to bitmaps (compatible with Access 2003 and earlier)


0 Display Navigation Pane

Ribbon and Toolbar Options

Ribbon Name;

Opening the Navigation Options dialog.

On the Navigation Options dialog, check the "Show System Objects" checkbox:

Navigation Options

Grouping Options

Click on a Category to change the Category display order or to add groups Categories Groups for "Tables and Related Views"

Tables and Related Views

IS tblCustomers


Object Type

(?] tblOrders



I?] tblShippers

f7\ tblOrderDe tails

|7] tblProducts


(?] tbllnfo

[7] tJkpReports

Add Item ]| Delete Item ][ Rename Item ]

Add Group ][ Delete Group ][ Rename Group

Display Options

|F| Show Hidden Objects Show System Objects □ Show Search Bar ^

Open Objects with © Single-dick # Double-dick

Turning on display of system objects in the Navigation Options dialog.

The following screen shot shows the USysRibbons table in datasheet view, with the record for the ListFields Ribbon visible:


n X

ID ' RibbonName


1 ListFields

<customUI xmlns=n">


<ribbon startFramScratch="false">


<tab id="dbCustomTab"

label="List Fields"


<group id="dbListingOptionsGroup"

label-1 Listing Options">

<button id="btnListTableFields"

label="List Table Fields"




on Act i on =" ListTa bl e Fi e Ids' '/>

<button id-'btnListQueryFields"

label-'List Query Fields"


i mageM so=" Create Query 1 n DesignV iew"

onAct ion =" ListQu e ryField s"/>






| Record: 14 il of 4 ► I

N K- | - ¿i 11Search i i

The USysDBRibbons table in datasheet view.

The USysDBRibbons table in datasheet view.

p, p • r-, rj r'r For more exhaustive coverage of XML, see Wrox's Beginning XML.

Although you can edit the XML code directly in the Access USysRibbons table (use Ctrl+Enter to go to a new line), it's a lot easier working with it in an XML editor, such as the one in VB 2005 (standard or Express), or the XML Notepad 2007 utility. Figure 15.4 shows what the same code looks like in the XML Notepad 2007 editor, after opening the code saved as Ribbon.xml.

IntelliSense doesn't work for Access Ribbon XML code in Visual Basic 2005 Express, but it does work in Visual Studio 2005.

It is much easier to work with XML code in the XML Notepad 2007 or the Visual Studio 2005 editor. In the XML Notepad 2007 editor, you have a TreeView pane on the left, and each attribute is shown with its matching value in the right pane; in the Visual Studio 2005 editor, the components are color-coded and you have IntelliSense to aid in creating code. Bracket matching (see the shaded <tabs> and </tabs> names in the figure) also helps, in case you started a bracketed code segment and forgot to end it. For XML code in the Visual Studio 2005 editor, the colors have the meanings listed in Table 15.3.


XML code in the XML Notepad 2007 editor.

ï] XML Notepad - G:\Unzip\Ribbon.xml j * I m El mÉ^gj

File Edit

View Insert Window Help


op i^ax § a a: m

Tree View XSL Output



L. xralns

3 ribbon

L. startFromScratch


3 Q tabs

B Ë3 tab

L, id


kf label

List Fields

C visible


¿J group




Li label

" 0|"t. i-ir«

H Öiütton!

k> id

H-..I1Í.I,■»•" -.: 1 -Kl f I'I.H


List Table Fields

V er.ab


V imag


V size


V onAc




Q >


Error List |


File Line


Loaded in 00:00:00

TABLE 15.3

Color-Coding for XML Code in the VB 2005 XML Editor


Code Component(s)


Attribute Name







Processing Instruction




XSLT Keyword

In order for XML documents to be able to use elements and attributes that have the same name but come from different sources, there must be a way to differentiate between different sources of markup elements. In XML, a namespace is a collection of names, identified by a URL reference, that are used as element types and attribute names in XML documents.

The XML code starts with specifying the namespace as office/2 0 06/01/customui. This is the only XML namespace used for Office 2007 Ribbons.

Next, the Ribbons startFromScratch attribute is set to "false" (for VBA programmers, note that in XML code, the syntax is "false", with the quotes, not just False, as in VBA code). This setting means that you are modifying the standard toolbar, as opposed to creating a Ribbon from scratch.

The next sections show how to customize the Ribbon in various ways.

Adding a New Tab, Group, and Controls to the Ribbon

To create a custom tab for the Ribbon, under the <tabs> section of the XML code, add a tab line and set its id and label attributes as desired. The id attribute is a unique identifier for a custom Ribbon control that can be used elsewhere in XML code to reference the tab, and the label attribute is set with the caption text to display on the tab. Set the tab's visible attribute to "true" to display it. Next, create one or more groups for the custom tab, setting their id and label attributes with the names and captions of the groups. Finally, add one or more controls to a group (or several groups) on the tab; for the sample XML code I created two buttons, each of which runs a callback function.

See Table 15.1 for a list of the most commonly used elements for creating tabs, groups, and controls on the Ribbon.

Controls have (minimally) id and label attributes, and also an enabled attribute (usually set to "true"). They typically display an image, which is usually set with imageMso argument, using a value corresponding to the standard Ribbon button that has the image you want to display.

You can't remove a control from a standard Ribbon group, or add a control to a standard group; see the sidebar earlier in this chapter for Patrick Schmid's illuminating commentary on this issue. For Microsoft's justification of this policy, see the Developer Overview of the User Interface for the 2007 Microsoft Office System article ( en-us/library/aa338198.aspx). It boils down to something like "We made the Ribbon perfect, so users don't need to customize it." Needless to say, I (and many other developers and power users) disagree. The Ribbon is indeed a great improvement over command bars and menus, but I would really like to be able to drag a button I need to a standard group, or remove one that I never use.

To use the Form image on a custom control, use "CreateForm" as the imageMso argument value when defining the button in XML code.

The controls size attribute has only two selections: "large" and "normal". Lastly, for a command button, set the onAction attribute with the name of a function to run when the button is clicked.

Was this article helpful?

0 0

Post a comment