Using the Object Browser

If you want to move easily through the myriad of VBA elements and features, examine the capabilities of the Object Browser. This special built-in tool is available in the Visual Basic Editor window.

To access the Object Browser, use any of the following methods: ■ Press F2

Choose View | Object Browser

Click the Object Browser button f|| on the toolbar

The Object Browser allows you to browse through the objects available to your VBA procedures, as well as view their properties, methods, and events. With the aid of the Object Browser, you can quickly move between procedures in your database application, as well as search for objects and methods across various type libraries.

The Object Browser window is divided into several sections. The top of the window displays the Project/Library drop-down list box with the names of all currently available libraries and projects. A library is a special file that contains information about the objects in an application. New libraries can be added via the References dialog box (select Tools | References). The entry for <All Libraries> lists the objects of all libraries installed on your computer. While the Access library contains objects specific to using Microsoft Office Access, the VBA library provides access to three objects (Debug, Err, and Collection) as well as a number of built-in functions and constants that give you flexibility in programming by allowing you to send output to the Immediate window, get information about run-time errors, work with the Collection object, manage files, deal with text strings, convert data types, set date and time, and perform mathematical operations.

Below the Project/Library drop-down list box is a search box (Search Text) that allows you to quickly find information in a particular library. This field remembers the last four items you searched for. To find only whole words, right-click anywhere in the Object Browser window and choose Find Whole Word Only from the shortcut menu. The Search Results section of the Object Browser displays the Library, Class, and Member elements that met the criteria entered in the Search Text box. When you type the search text and click the Search button , Visual Basic expands the Object Browser window to show the search results. You can hide or show the Search Results section by clicking the button located to the right of the binoculars.

In the lower section of the Object Browser window, the Classes list box displays the available object classes in the selected library. If you select the name of the currently open database (e.g., Northwind) in the Project/Library list box, the Classes list will display the objects as listed in the Explorer window. In Figure 2-14, the Form_Employees object class is selected. When you highlight a class, the list on the right side (Members) shows the properties, methods, and events available for that class. By default, members are listed alphabetically. You can, however, organize the Members list by group type (properties,

Introduction to Access 2003 VBA Programming

Project/Library list box" Search text box -

The search results -appear here

Code template -

Project/Library list box" Search text box -

The search results -appear here

Code template -

Figure 2-14: The Object Browser window allows you to browse through all the objects, properties, and methods available to the current VBA project.

methods, or events) using the Group Members command from the Object Browser shortcut menu (right-click the Object Browser to display this menu).

If you select the Northwind project in the Project/Library list box, the Members list box will list all the procedures available in this project. To examine a procedure's code, double-click its name. If you select a VBA library in the Project/Library list box, you will see the Visual Basic built-in functions and constants. If you need more information on the selected class or member, click the question mark button located at the top of the Object Browser window.

The bottom of the Object Browser window displays a code template area with the definition of the selected member. If you click the green hyperlink text in the code template, you can jump to the selected member's class or library in the Object Browser window. Text displayed in the code template area can be copied and pasted to a Code window. If the Code window is visible while the Object Browser window is open, you can save time by dragging the highlighted code template and dropping it into the Code window.

You can easily adjust the size of the various sections of the Object Browser window by dragging the dividing horizontal and vertical lines.

Now that are familiar with the Object Browser, you can put it to use in VBA programming. Let's assume that you want to write a VBA procedure to control a check box placed on a form and would like to see the list of properties and methods that are available for working with check boxes.

© Hands-On 2-2: Using the Object Browser

1. Switch to the Visual Basic Editor window and press F2 to open the Object Browser.

2. In the Project/Library list box of the Object Browser, click the drop-down arrow and select the Access library.

3. Enter checkbox in the Search Text box and click the Search button (#4).

Part I

Make sure you don't enter a space in the search string. Visual Basic begins to search the Access library and displays the search results. By analyzing the search results in the Object Browser window, you can find the appropriate VBA instructions for writing your VBA procedures. Looking at the Members list, you can quickly determine that you can enable or disable a check box by setting the Enabled property. To get detailed information on any item found in the Object Browser, select the item and press F1 to activate online help.

0 0

Post a comment