Microsoft Access VBA Macro Programming

(Tina Sui) #1
By selecting the drop-down Choose Commands From in the top-left corner of the form,
you can select control lists in any of the menu tabs or any of the other groups available. You
can even see the custom tab called Contoso that you created earlier.
If you select one of these options, you will then see all the controls and groups associated
with it. If you hover your cursor over any of the controls, you will see its name in brackets at
the end of the tooltip string.
One important rule is that the list shows both groups and controls within those groups.
The controls have icons; the groups do not. If you try to use this code on a group name, you
will get an error. For example, GroupFont is a group (there is no icon next to it), so the
statement

MsgBox Application.CommandBars.GetEnabledMso("GroupFontAccess")

will give an error. However, if you substitute “FontSize” for “GroupFontAccess” the code
will run correctly.
As already stated, you can see the custom ribbon group you created earlier called Contoso.
If you hover your cursor over your custom controls, you will see that they all have names, but
the sad thing is that they all have the same name (CustomControl) and you cannot access
them by using this code.
You can use the following methods in conjunction with the existing controls within
Access:

 ExecuteMso Runs the control as if the user had clicked it.
 GetEnabledMso Returns True or False according to whether the control is enabled.
 GetImageMso Returns the control image into a variable defined as IPictureDisplay.
You also need to define width and height.
 GetLabelMso Returns the label for that control, which is often the same as the name.
 GetPressedMso Applies to a check box and toggle buttons and returns true if the
control has been pressed.
 GetScreentipMso Returns the string for the screentip of that control. This is often
the same as the name and the label.
 GetSupertipMso Returns the super screentip for the control and is usually more
descriptive.
 ReleaseFocus Releases the focus on the command bar object.
 GetVisibleMso Returns True or False for a given ID of an Mso (Microsoft Office
control).

You can also use the parameters defined in the callback code to access user actions, such as
if the user checked a check box or entered some text into an edit box. You will see examples
of this further on in this chapter.

140 Microsoft Access 2010 VBA Macro Programming

Free download pdf