Seeking help with properties and methods

When you're typing VBA statements that involve objects, properties, and methods, you get all the usual quick-reminder Help on-screen. You can always get more help, though. For example, as soon as you type DoCmd. (remember to type the period as per the syntax for DoCmd), you see a menu of methods that DoCmd provides, as in Figure 5-7. The menu is lengthy, so you have to use the scroll bar to see all the available methods of the DoCmd object.

Figure 5-7:

Menu of valid entries for the first word after

DoCmd.

VBA Practice - Modulel (Code)

| (General)

Tesl

zi

Sub Test DoCn

-

CancelEvent ClearMacroError

Ê

-

Close Data base

V

-1

After you type a method name and a blank space, you see the entire syntax for the method in a Quick Info screen tip, as in Figure 5-8. For the lowdown on how to read Quick Info tips (what all the brackets, bold, italics, and other elements mean), check out Chapter 3.

Figure 5-8:

Get Quick Info syntax help.

Figure 5-8:

Get Quick Info syntax help.

As always, quick reminders don't provide any detail. When you're first finding out how to master VBA, frequent visits to the VBA Help are necessary. VBA has far too many objects, properties, methods, and keywords to list them all in this book (or even a 1,000-page book). The best skill that you can learn in VBA is how to get exactly the help you need, when you need it.

Fortunately, all the Help methods that work with other VBA keywords also work with objects, properties, and methods. For example, for help with the OpenForm method of the DoCmd object, you can do the following:

^ In the Code window: Type DoCmd.OpenForm into the Code window, double-click OpenForm to select it, and then press F1 for Help.

^ In the Object Browser: Find DoCmd in the left column, click OpenForm in the right column, and click the Help (?) button in the Object Browser.

As always, a Help window pops up, as in the example shown in Figure 5-9, where you can get more information on the OpenForm method.

Selected keyword

Figure 5-9:

Help for the

OpenForm method.

Selected keyword

Figure 5-9:

Help for the

OpenForm method.

Help for selected keyword

Trying to figure out how to write a line of new code, or modify an existing line of code by just guessing, is likely to turn into an exercise in hair-pulling frustration. Nobody was ever born already knowing VBA syntax, and even the experts have to make frequent visits to Help to get specific information when they need it. The Help system in VBA is your best friend. Use it well!

0 0

Post a comment