Part IV: Professional Database Development
1024
Here is an example. The following XML statements define a button control on a ribbon:
<button id=“ViewProducts”
label=“All Products”
size=“large”
imageMso=“FindDialog”
onAction=“OpenProductsForm”
tag=“frm ProductsDisplay”/>
(These lines appear as a single statement in the XML code behind the Collectible Mini Cars Main2
ribbon.)
Notice the onAction attribute in this XML code. Notice also that the onAction attribute is set
to onOpenFormEdit. The onAction attribute is similar to the events associated with a form’s
controls. Each interactive ribbon control (buttons, SplitButtons, and so on) include the onAction
attribute. The callback procedure (onOpenFormEdit, in this example) assigned to the on
Action attribute is passed to the ribbon processor when the control’s action occurs.
A control’s attributes may appear in any order within the control’s XML, but they must be spelled
correctly. XML is notoriously case sensitive, so attributes must be entered exactly as you see in the
examples in this chapter and in the Chapter29.accdb example database. And, attribute values
(like “FindDialog”) must be surrounded by double or single quote characters.
Notice that the button control does not contain a click event. Instead, each interactive control’s
onAction attribute handles whatever action is expected by the control. In the case of a button,
the action is a user clicking the button, whereas for a text box, the action is the user typing into the
text box. Both of these controls include the onAction attribute, but onAction means something
different for each control.
Note
Be aware that onAction is not an event. It is just an XML attribute that points to the callback procedure tied
to the ribbon control. The callback procedure runs whenever the user interacts with the control. In this case,
the ViewProducts button’s callback procedure is invoked when the user clicks on the button.
Ribbon controls have several other important attributes, such as imageMso, screenTip, and super-
tip. These attributes are described in the “Adding Ribbon Controls” section, later in this chapter.
Tip
You probably want to see any errors generated by your custom ribbon during development. By default, ribbon
error reporting is disabled, and you must enable it before you see error messages thrown by the ribbon. Click
the File tab in the upper-left corner of the main Access screen and choose the Options button at the bottom.
Next, select the Client Settings tab in the Options dialog box and scroll down to the General section. Make
sure the Show Add-In User Interface Errors check box is selected; click OK at the bottom of the dialog box.
The error messages generated by the ribbon are invaluable debugging aids (see Figure 29.14). Without these
messages, you have no idea what has failed in your custom ribbons.