Microsoft Access VBA Macro Programming

(Tina Sui) #1
<editBox id="Editbox 1 "
label="Editbox sample"
onChange="MyChange"
/>

</group>
</tab>
</tabs>
</ribbon>
</customUI>

Copy and paste your XML code into the Ribbon XML field of USysRibbons table. Exit
the database and then reload it. If you now click the Home menu item, you will see that your
custom ribbon control, My Control, now has a text entry box as well as your original check
box. If you type something into the text box and pressENTER, you will get an error message
because the callback to MyChange has not yet been defined.
Again, to create the callback, click the callback icon in the Custom UI Editor and copy
and paste the code for Editbox1onChange. This is a very useful feature because it gives you
the correct passing parameters within thecallbacksubroutine. The checkbox control had a
parameter calledpressedthat was a Boolean (True or False), whereas the text box has atext
parameter to hold the value that the user typed in.
Your callback code should now look like this:

Sub MyChange(control As IRibbonControl, text As String)
MsgBox text
End Sub

This simply provides a message box to show what has been typed in. Go back to the
spreadsheet and click Home on the menu bar. Enter some text into your new text box on the
My Control ribbon control and pressENTER. Your text will then be displayed in a message
box on screen.
Suppose you want to include something more complicated in your ribbon control such as
a combo box (a drop-down control). This can also be accomplished in a fairly straightforward
manner.
In the Custom UI Editor, add in the following XML below your edit box XML:

<comboBox
id="MyCombo"label="My Combo"
onChange ="OnChange"
getItemCount ="GetItemCount"
getItemLabel ="GetItemLabel"
/>

144 Microsoft Access 2010 VBA Macro Programming

Free download pdf