Microsoft Access VBA Macro Programming

(Tina Sui) #1

Copy the skeleton code from the Custom UI Editor window by selecting all of it and
pressingCTRL+C. Select the module on the VBA Editor window and pressCTRL+Vto paste it
into your code. Your screen should now look like Figure 11-5.
If you go back to your Access form, select your custom ribbon group and click one of the
buttons, you will now find that no error message appears. Nothing actually happens, but just
copying in the skeleton code has provided code for theOnActionparameter and has
suppressed the error message.
You now need to add some code into the callback code to make the buttons do something.
You can create the code for the first button as follows:


'Callback for customButton 1 onAction


Sub conBoldSub(control As IRibbonControl)
Screen.ActiveControl.FontBold = True
End Sub


This simply sets the active control on your form (the control with the focus) to bold. Pretty
simple stuff, but by using your imagination you can go a lot further on this.


Chapter 11: Working with the Ribbon 137


Figure 11-5 The VBA Editor window showing the skeleton callback code

Free download pdf