Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 29: Customizing Access Ribbons


1023


Developing Custom Access Ribbons


Ribbons are not represented by a programmable object model in Access. Each ribbon is defined by
XML statements contained in a special table named USysRibbons. Access uses the information it
finds in the XML to compose and render the ribbon on the screen.

The ribbon creation process
Briefly, creating custom ribbons is a five-step process:


  1. Design the ribbon and compose the XML that defines the ribbon.

  2. Write VBA callback routines (described in the following section) that support the ribbon’s
    operations.

  3. Create the USysRibbons table.

  4. Provide a ribbon name and add the custom ribbon’s XML to the USysRibbons table.

  5. Specify the custom ribbon’s name in the Access options screen.


None of these steps is particularly intuitive, especially when it comes to composing the XML and
writing callback routines. Your best bet is to find an example that is reasonably close to what you
want and customize its XML to suit your purposes.

Using VBA callbacks
A callback is code that is passed to another entity for processing. Each procedure you write to sup-
port operations on a ribbon is passed to the “ribbon processor” in Access that actually performs the
ribbon’s actions. This is very unlike the event-driven code you’ve been working with in Access.
Clicking a button on a form directly triggers the code in the button’s Click event procedure. A
ribbon’s callback procedure is linked to the ribbon, but is internally processed by Access and does
not directly run in response to the click on the ribbon.

To fully understand this process, imagine that Access contains a process that constantly monitors
activity on the ribbon. As soon as the user clicks a ribbon control, the ribbon processor springs
into action, retrieving the callback procedure associated with the control and performing the
actions specified in the callback.

This means that there are no Click, DblClick, or GotFocus events associated with Access rib-
bons. Instead, you bind a callback to a ribbon control through the XML that defines the ribbon.
Each ribbon control includes a number of action attributes that can be attached to callbacks, and
the ribbon processor takes over when the user invokes a control’s action.
Free download pdf