

The procedure in Listing B lists information about the controls on any menu bar, toolbar, or pop-up menu.Įnter the following statement in the Immediate window: In a custom control, you could use the Tag property to store a name if you need to present names to the user. To identify a control, use the Caption property, the Index value, or the ID property (which is assigned internally). Unfortunately, the CommandBarControl object is more limited in properties than the more specific control objects.įor example, the CommandBarControl object doesn’t have a Name property. These aren’t types of objects they’re the type of controls you’ll encounter via each of the three above objects.īecause a command bar can contain different types of control objects, you’ll probably find working with the generic CommandBarControl object less complicated and more dependable than the others-at least in the beginning. There are many control types at this level Table B lists the more common ones. CommandBarPopup : A control that displays another menu when you click on it.CommandBarComboBox : A custom combo box on a command bar.CommandBarButton : A button control that displays text, an icon, or both on a command bar.

More specifically, these controls can be one of three specialized objects: Most of the pop-up types are listed toward the bottom of the list.Įach CommandBar object contains any number of CommandBarControl objects. If you scroll through the list in the Immediate window, you’ll find only one menu bar (type 1). Refer to Table A for the types of CommandBar objects. List all the CommandBar objects in an application. (The list is actually very long Figure A displays only the first few items.) It then lists each object by name, specifies whether it’s enabled or disabled (True and False, respectively), and identifies the object by type. Enter the procedure in Listing A in a standard module and then run the procedure by clicking the Run Macro button on the VBE’s Standard toolbar.įirst, this simple function returns the number of CommandBar objects in the collection, which in our example is 173, as you can see in Figure A. The menu bar and toolbars don’t look the same, but underneath what you see, they’re both the same type of object-the CommandBar object.Ĭycling through the CommandBars collection, which represents all the CommandBar objects for a particular application, is a simple task. In contrast, a view can present many toolbars, which then present buttons and tools, that perform a task when clicked. Each menu command on the menu bar performs a task or presents a submenu. The menu bar-named Menu Bar-is actually the current menu bar in any particular view, and each view has just one. Click OK to close the References dialog box.Įach menu bar, toolbar, and pop-up menu is a CommandBar object that consists of a collection of control objects. Then check the Microsoft Office 10.0 Object Library item. To do so, launch the Visual Basic Editor (VBE) and select the References option from the Tools menu. To interact with the command bar object model, you must reference the appropriate library.
BAR ACCESS HOW TO
In this article, I’ll consistently apply the same syntax to the different levels of the model so you can see both visually and programmatically how to interact with the model levels. Working through the object model and identifying which object is at every level is the key to correctly referencing objects so you can manipulate them via Visual Basic for Applications (VBA) code. In Access, these built-in objects are the menu bar, a variety of toolbars, and pop-up menus, and they’re stored with the database in which they’re created-unlike the other applications that store the command bars separately. Each Office application contains dozens of built-in command bar objects, which in turn can contain dozens more command bars. The Office Command Bar object model has a lot to offer but is also a bit awkward to work with if you don’t know exactly what you’re doing. You may even build custom toolbars with the same goal in mind.

To this end, you’ll probably suggest that built-in toolbars be totally inhibited or at least modified to present only those items the user really needs to access. It can also keep users out of trouble by limiting the number of options they can execute. It’ll help your users learn how to use the application more quickly. Here's a detailed look at properly using the Office Command Bar object model.Īn easy-to-use interface is always an appreciated commodity in an application. Working with the command bar and controls can be frustrating. Referencing command bar and control objects in AccessĬonsultants who design applications in Access are familiar with the Office Command Bar object model.
