Using the Object Browser

The Object Browser is probably one of the most powerful tools you'll use when writing VBA code. You can display the Object Browser by selecting Object Browser from the View menu of the VBA Editor or by clicking F2 within the VBA Editor. The Object Browser, shown in Figure 5-2, has a number of components.

When you load the Object Browser, you'll notice that you can still view the Project Explorer and the Properties window. The Object Browser appears directly over the Code window. You can return to the Code window at any time by selecting Code from the View menu or by clicking F7. There are several components of the Object Browser you'll use often.

□ The Project/Library box shows all the available type libraries. We'll discuss how to add a type library to your Project later in this chapter. You can choose any available type library from the drop-down box or choose <All Libraries>. The type library you choose in the Project/Library box will dictate which objects you can browse with the Object Browser.

□ The next drop-down box is the Search text box. You can enter search terms in that box and click the Search button (the icon of the binoculars) to search the selected type libraries for the particular term. Results of your search are displayed in the Search Results pane.

□ The Search Results pane lists all of the results of your search. You can show or hide the Search Results pane by clicking the Show/Hide icon (two up or down arrows) next to the

4m Microsoft Visual Basic - VBA Samples -

[Object Browser]

Sj File Edit View insert Debug

Run lools Add-lns Window Help

Type a question for help

T . J x

IB IH l> * Ift HJ > il

iu a 1 « & * 1 m 1

Project - VBA Samples Q

Project - VBA Samples Q

bM

VBA Samples (VBA saint

El

Microsoft Office Access

I-ÉI Form_fr m .Samples

s'

Ö Modules

■■Ä Module!

' ■ Samples

ft

n Class Modules

<1 1 M

Properties - Sample

¡Samples Module

Properties - Sample

¡Samples Module

Alphabetic | Categorized ]

Search Results -

Classes

Members of'«globals»'

O hglütialss

H

n

A_

ADD

® AccessOtiject

_1

S

A_

_ALL

iS AccessOb|ectPro|iei

Ei

A_

ANYWHERE

üSl AccessObjectProper

A.

.ATTACH

# AcCloseSave

B

A_

„COPY

i=P AcColorlndex

i

A_

.CURRENT

rjp AcCommand

El

A_

_CUT

& AcControlTyfje

^J

A_

.DELETE

■Sp AcCurrentView

m

A_

DELETE_V2

# AcDataAcceésPage\

m

A.

.DESIGN

•ip AcDataOtijectType

El

A_

.DIALOO

<=p AcDataTransferType

d

El

A_

.DOWN

'ip AcDefVlew

El

A

DRAFT

sAII Libraries^

■R...| g]5...| Jv...|afr...|[m: ^SJ...| LÖ] I... I i^^KilP 10:34 AM

Search button. The Search Results pane lists the relevant library, class, and member of any object returned by your search. To display more information about any object displayed in the Search Results pane, click the object to display its full information in the Details pane.

□ The Classes list displays all of the objects, enums, and collections in the currently referenced library. You can scroll through the Classes list and click to select any of the listed items. After you select an item, more details are displayed in the Members of list and the Details pane.

□ The Members of list displays all of the properties, methods, events, and constants associated with the currently selected object in the Classes list. Select any of the items in the Members of list to display details in the Details pane.

□ The Details pane of the Object Browser displays information such as the type of object, its data type, the arguments it needs, and the parent library or collection. For example, in Figure 5-3, the Details pane informs you that the constant vbOkOnly is a member of the Enum vbMsgBoxStyle, which is a member of the VBA object library. Its value is 0 and the other members of the Enum vbMsgBoxStyle include vbApplicationModal, vbCritical, vbExclamation, and many others.

All Libraries vhokonl.v Search Results

Library

Class

Member

VbMsgDoxSlyle m vbOKOnly

Classes

Members of VbMsgSoxStyle'

VbDateTlrneFormat

iZi

■yb Information

dp VbDayOtWeek

iZ)

vbMsgBoxHelpBiJtion

gF VbFNeAttribute

CD

vbMsgBoxRight

(¿P VbFirstWeekOiYear

CD

vbMsgEloxRtlReading

dp VbiMEStatus

CD

vbMsgBoxSetForeground

¿P VbMsgBoxResult

®

vbOKCancel

¿FjVbMsgBoxStyle

©

r bOKOnly

VbQueryClose

©

vbQuestion

f# VbStrConv

CD

vbRetryCancel

□5s VbTri State

CD

vbSystemModal

VbVarType

CD

vbYesNo

gig WehOptions

_l tJ

CD

vbYesNoCancsl

ttA Workspace

Member of VBA.tfbMsiiBoxStvte

Figure 5-3

If a Help file is associated with the currently selected object, you can display a Help topic by clicking the item in either the Classes or Members of list, and then pressing F1 or clicking the Help button in the upper-right corner of the Object Browser.

The buttons next to the Project/Library box allow you to scroll through the previous or next members of the current collection.

One of the advantages of the Object Browser is that you can actually use it to take you to anywhere in the code the current object is declared. For example, in Figure 5-3, I've searched the current database's object library (Samples) for the procedure CoffeeTime. The Search Results pane lists the library, class, and member for the CoffeeTime sub. You can click the View Definition button (the fourth button from the left next to the Project Library drop-down box) to return to the Code window and display the CoffeeTime sub, as shown in Figure 5-4.

The rest of this chapter will explore the other components of the VBA Editor that can help you write and debug VBA code.

Was this article helpful?

0 0

Post a comment