Microsoft Access VBA Macro Programming

(Tina Sui) #1

As you have already seen, you can add code to a control and you can change the title of a
ribbon group, but this can only take place when the Access file is loaded in.
Access 2010 has over 1,700 ribbon controls, and each has a name. Use this name to
identify the control in the collection when you are working with it.
A simple example of code to access a ribbon control is as follows:


MsgBox Application.CommandBars.GetEnabledMso("FileSave")


This code can be run from any module in your application and does not have to be on a
form or report. Use a standard VBA message box that you used back in Chapter 1. This should
returnTruein that the FileSave control is enabled. Note that these names are case-sensitive
and if you put in “filesave,” this will produce an error.
The next question is, how do you get the name of a particular control with so many
available? To do this, you need to place your cursor on the ribbon bar of the Access window
and right-click. Take the option Customize Quick Action Toolbar or pressC. You will see a
form displayed as shown in Figure 11-6.


Chapter 11: Working with the Ribbon 139


Figure 11-6 The Customize Quick Action Toolbar screen

Free download pdf