How to: Take over a ribbon written by hand
Open a ribbon whose RibbonXML was written by hand in the USysRibbons table in the ribbon designer, so that you can edit it there from now on.
Requires WKL Forms Object Library 1.58 or later.
Solution overview
When the database has rows in USysRibbons that the ribbon model doesn't own, the Ribbons page of
the ribbon designer shows the Existing ribbons card with their names. Read in reads the
RibbonXML of each row into the model: tabs, groups, buttons, toggle buttons, menus, split buttons,
separators, built-in commands (idMso), and custom File view tabs with their tasks. Each custom
control becomes a command named after its id; a control with idMso becomes a command with the
action Built-in command (idMso), shared by every place that names it.
Nothing is written until you click OK or Apply in the designer: saving replaces the
taken-over rows in USysRibbons with the generated XML and writes the callback module. Cancel
leaves the database as it was. When the database property CustomRibbonID names a taken-over
ribbon and the model doesn't have an application ribbon yet, that ribbon becomes the application
ribbon.
Implementation
- Open the ribbon designer (the WKL Ribbon Designer add-in entry, or
WklRibbon.ShowDesignerfrom VBA). - On the Ribbons page, in the Existing ribbons card, choose Read in.
- Read the list below the button: each line names a part that was left out or simplified.
- Fix what the list names (see Remarks), check the Check page, and then choose OK.
- Close the database and open it again; Access applies ribbons when the database opens.
An onAction callback must become a function without arguments. Before:
<button id="btnCustomers" label="Customers" onAction="OnCustomers"/>
Public Sub OnCustomers(control As IRibbonControl)
DoCmd.OpenForm "frmCustomers"
End Sub
After the takeover, on the Commands page, give the command btnCustomers the action Open
form with frmCustomers, or the action Call VBA function with:
Public Function OpenCustomers() As Boolean
DoCmd.OpenForm "frmCustomers"
OpenCustomers = True
End Function
An onAction written as an expression (onAction="=OpenCustomers()") is taken over as the action
Call VBA function OpenCustomers, without a note.
Remarks
| In the XML | After the takeover |
|---|---|
onAction that names a procedure | The command has no action; a note names the procedure. |
getLabel, getVisible, getEnabled, getImage, and other get… callbacks | Left out with a note; the static value (for example, label) stays. For dynamic values, use the command's condition and the runtime object. |
onLoad, loadImage | Left out with a note; the generated module has its own. |
comboBox, editBox, dropDown, gallery, checkBox, dynamicMenu, labelControl, dialogBoxLauncher | Left out with a note. |
box, buttonGroup | Dissolved: their controls stay in the group. |
splitButton inside a menu | Becomes a menu with the command of its button. |
Built-in tab or group (idMso on tab or group) | Left out with a note. |
qat, contextualTabs, commands, contextMenus | Left out with a note. |
visible="false" on a custom element | Left out with a note. |
Built-in File view entry with visible="false" | Kept: listed as hidden in the File view. |
image that names a picture whose name isn't valid | Left out with a note. |
id that isn't a valid name or is already in use | Made valid and unique (tab.Start becomes tab_Start, and a second btnCustomers becomes btnCustomers_2). |
Your own callback procedures stay in your modules, but the generated ribbon no longer calls them. Remove them once the commands have their actions.
Related topics
- WklRibbon: the ribbon model, designer, and runtime.
- How to: Control the ribbon from code: labels, visibility, and states at run time instead of
get…callbacks. - How to: Show commands only in development: conditions instead of
getVisible.