5.1. Anatomy of the VBA Editor

You can access the VBA Editor in several ways. From anywhere in Microsoft Access, click Alt+F11 on the keyboard or choose Tools, Macro, Visual Basic Editor. You can also enter the VBA Editor from any Form or Report. From the Properties dialog box, click the Events tab, select the event you're interested in, click the Ellipses button (. . . ), and choose Code Builder. When you first view the VBA Editor, you might be a little overwhelmed by the number of components you see on the screen. Let's view the VBA Editor within a user-created module, as shown in Figure 5-1

The VBA Editor shown in the figure has the following components:

  • Project Explorer: This window shows you all of the components of the current VBA Project. The various components can include three types of objects: form or report modules, class modules, and standard modules. Each type of component has its own icon. The Project Explorer in Figure 5-1 contains a class module, a source form, and a standard module. The VBA Project carries the same name as the current database. If for any reason, the Project Explorer isn't visible when you display the VBA Editor, click Ctrl+R to display it.

  • Properties Window: This dialog box, typically shown on the bottom-left corner of the VBA Editor, lists all of the properties for the currently selected object. The object could be a module or a class module. You probably won't use the Properties window often when writing VBA code in Access 2003. This window is more helpful when working with user forms in Visual Basic.

    Figure 5.1. Figure 5-1
  • Code Window: This is where you'll actually write your code. By default, the Code window displays all subs and functions within the current module. You can change the display of the Code window and limit it to only the currently selected procedure by selecting Options from the Tools menu. In the Window Settings frame of the Editor tab, uncheck Default to Full Module View. Click OK to save your changes. The Code window has several components of its own.

  • The Object list box allows you to choose from a variety of objects. When you're writing code inside a standard module, this list box will only contain the (General) option. When you're writing code within a class module associated with a form or report, the Object list box contains an entry for every object (text box, combo box, label, and so on) within the form or report.

  • The Procedure list box displays different items depending on the type of module you're viewing. When viewing a class module associated with a form or report, the Procedure list box contains an entry for every event associated with the selected object. For example, if you choose a combo box on your form, the Procedure list box contains an entry for events such as the Click event, the BeforeUpdate and AfterUpdate events, and the LostFocus event, among others. If you're viewing a standard module, this list box contains an entry for every sub or function in your module. You'll use this drop-down list to select the specific procedure you need to edit. If you have a module with a large number of procedures, scrolling through the Code window to find the specific procedure can be a time-consuming and onerous task. Simply click the Procedure drop-down box to choose any available procedure in the current module or class module. All subs and functions are listed alphabetically. You can also use the Procedure drop-down box to jump directly to the General Declarations section.

  • The Code window is where you'll actually write your code. You can include subs, functions, and general declarations.

In addition to these visible components, there are a number of components you can display to help you write your code and work with the Access 2003 Objects. Most of these components are available under the View menu within the VBA Editor.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.147.160