Part IV: Professional Database Development
1028
The callback procedure for the check box uses the pressed parameter to determine which path to
take through the procedure:
Public Sub onAction(control As IRibbonControl, _
pressed As Boolean)
If pressed = True Then
DoCmd.OpenForm “frmHelp”
Else
DoCmd.Close acForm, “frmHelp”
End If
End Sub
We’ve been focusing on the onAction callback, but many other callbacks exist. Here is the XML
definition of a simple Label control:
<labelControl id=“lblTodaysDate” getLabel=“onGetLabel”/>
Notice the getLabel attribute. The callback signature of the getLabel attribute is
Public Sub onGetLabel(control as IRibbonControl, ByRef label)
The Label control is passed as the IRibbonControl parameter, and the label’s contents are
passed as the (variant) label parameter. Notice that the label parameter is passed by reference,
allowing the callback to modify the parameter’s value. An example procedure for filling a label with
the current date is
Public Sub onGetLabel(control as IRibbonControl, ByRef label)
label = “Today is: “ & FormatDateTime(Date, vbLongDate)
End Sub
The attribute linked to this callback is getLabel, which designates the procedure that fills the
label’s text at runtime. The name of the callback (onGetLabel) can be anything, but it makes
good sense to provide it with a name that links it to the control’s getLabel attribute.
Notice that none of these callback procedures discussed so far reference the control by name. This
means that you have to write a uniquely named callback for each control, or use a single callback
for multiple similar controls. Several of the Collectible Mini Cars callbacks use the control’s id
property to determine which control has triggered the callback:
Public Sub onGetLabel(control As IRibbonControl, ByRef label)
Select Case control.id
Case “lblWelcome”
label = GetWelcomeMessage()
Case “lblToday”
label = “Today is: “ & FormatDateTime(Date, vbLongDate)
Case “lblOrderCount”
label = GetSalesCountString()
Case “lblCompany”
label = “Name: “ & DLookup(“Company”, “tblContacts”)