Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 29: Customizing Access Ribbons


1041


The first callback (onGetLoginCount) gets the count of items to be placed on the DropDown’s
list. Notice the ByRef count parameter. This parameter tells the DropDown how many items to
accommodate on its list.


The second procedure (onGetLogins) actually retrieves the items for the list. In this case, the
procedure pulls the SalesPerson name field from tblSalesPerson using DLookup. onGet-
Logins is called by the DropDown multiple times; the exact number of calls is determined by the
count value established by onGetLoginCount.


The onGetLogins routine cheats a little bit to supply this information. Notice the index parame-
ter passed to this routine. Index tells the procedure which slot on the drop-down list is being filled
when the procedure is called. The DLookup adds 1 to this value and extracts the name of the sales
person whose ID matches this value. This means that the SalesPersonID values have to be
sequential, starting with 1, or this procedure will fail.


Extracting data with nonsequential ID values, or where the ID value is non-numeric, requires a bit
more work. You could, for instance, create a sorted recordset of the values you want on the list.
Then, using the index parameter, advance through the recordset to the record requested by the
DropDown.


An accurate count of values to add to the DropDown is important. The DropDown has no way,
other than the count parameter, to know how many items to expect. Setting a count too low means
that not all items will be added, whereas setting the count too high means that list contains blank
spaces. If, for instance, you set the count to 10 items, but only 5 are available, the DropDown’s list
contains the five items, but also five blank spaces.


The SplitButton Control


The SplitButton control is very useful in situations where the user may select from a number of dif-
ferent options, but one option is used more frequently than the others. An example might be a
number of reports, one of which is commonly printed, and the others are printed only periodically
(a SplitButton example is shown in Figure 29.4).


The items on a SplitButton’s list are contained within

and tags. Whatever con-
trols (within reason, of course) that appear within these tags show up in the SplitButton’s list. The
definition of the default button portion of a SplitButton lies outside of the and
tags. In the following code fragment, MyButton1 is the default button, whereas the other buttons
(MyButton2, MyButton3, and so on) occupy the SplitButton’s list.


<customUI xmlns=“http://schemas.microsoft.com/office/2006/01/
customui”>
<ribbon startFromScratch=“true”>
<tabs>
<tab id=“RibbonControls” label=“RibbonControls”>
<group id=“MyGroup” label=“Split button”>
<splitButton id=“MySplitButton” size=“large”>
<button id=“MyButton1”
imageMso=“ModuleInsert”
Free download pdf