Introducing the VBA Modules

 < Day Day Up > 

After launching the VBE, you'll probably want to view existing code or enter new code. All VBA code is contained in one of three types of modules:

  • Standard Contains code that's independent of a specific object.

  • Object Contains code that responds to the attached form or report. If you're already writing event procedures, you're doing so in these modules. Each form and report in an Access database can have its own object module.

  • Class Contains code that defines custom objects. You'll learn about class modules in Chapter 8, "Understanding Objects"

To insert a standard or class module, choose Insert, Module or Insert, Class Module, respectively. Access responds by inserting the appropriate type module.

Figure 2.4 shows a standard module in the VBE. Notice how inserting a new module updates the contents of both the Project Explorer and the Properties window. Enter procedures that are independent of any objects or events in a standard module. You can use objects and events in the code, but the module itself isn't defined by an object nor does it contain any predefined events.

Figure 2.4. Modules contain the VBA code that automates your database.

graphics/02fig04.jpg


Object modules come with the forms or reports you create. They're really a type of class module, but you don't have to reinvent the wheel every time you want to add code to a form or report. These modules come with your forms and reports. The code in an object module is usually triggered by and responds to the object's events. However, an object module can contain a procedure that's not related to an event.

TIP

There are a number of keyboard shortcuts for moving around the VBE. Many of these are listed in Table 2.1, but there are many others. For instance, pressing Shift+F10 displays the active window's shortcut menu. (You can also display this menu by right-clicking the window.) To learn more shortcuts, search in the special VBA Help files for "Keyboard Shortcuts."


     < Day Day Up > 


    Automating Microsoft Access with VBA
    Automating Microsoft Access with VBA
    ISBN: 0789732440
    EAN: 2147483647
    Year: 2003
    Pages: 186

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net