Your First Glance at the Visual Basic Editor

 < Day Day Up > 

The Visual Basic Editor (VBE) is the interface you'll use to write VBA code. Figure 2.1 shows the VBE window for the TimeTrack sample database. The easiest way to launch the VBE is to open Access, load the database, and then press Alt+F11. (If you're following along with an existing database, the VBE may display some code when you first open it.)

Figure 2.1. Welcome to the Access Visual Basic Editor.

graphics/02fig01.jpg


In this chapter, we'll introduce you to the many components you'll be working with and even let you enter a bit of code. We won't spend a lot of time learning about every single element, tool, and menu command in the VBE you'll learn about them later by actually using them as you produce example code. For now, just familiarize yourself with the development environment so you'll be on friendly ground later.

By default, the VBE displays the following components:

  • The menu is the default menu.

  • The Standard toolbar is the default toolbar.

  • Project Explorer displays a hierarchical list of the items contained and referenced in the current database.

  • The Properties Window is a simple interface for displaying and modifying object properties.

  • The Immediate window displays the results of code.

TIP

Individual windows in the VBE are dockable, just like most menus and toolbars. Double-click the title bar of a window to toggle docked and floating.


Table 2.1 describes the tools on the VBE's standard toolbar, which is shown in Figure 2.1. These are the tools you'll use most of the time.

Table 2.1. The Standard Toolbar

Name

Purpose

Keystroke Combination

Menu

View Microsoft Office Access

Displays the Access 2003 window without closing the VBE window.

Alt+F11

View, Microsoft Office Access

Insert Module

Creates a new and empty module. Choose a module type from the tool's drop-down list.

 

Insert, Module

Find

Searches for a specific word or phrase in the module.

Ctrl+F

Edit, Find

Undo

Cancels the last keyboard stroke or the last mouse operation (when possible).

Ctrl+Z

Edit, Undo

Redo

Cancels the last Undo action (when possible).

 

Edit, Redo

Run Sub/ UserForm

Executes the current procedure or continues execution after a procedure has been paused by a break condition.

F5

Run, Run Sub/UserForm

Break

Halts a procedure.

Ctrl+Break

Run, Break

Reset

Terminates a procedure and reinitializes all variables to their default values.

Shift+F5

Run, Reset

Design Mode

Toggles to UserForms design mode.

 

Run, Design Mode

Project Explorer

Opens the Project Explorer.

Ctrl+R

View, Project Explorer

Properties Window

Opens the Properties window.

F4

View, Properties Window

Object Browser

Opens the Object Browser window.

F2

View, Object Browser

Toolbox

Displays the Toolbox.

 

View, Toolbox

VBA Help

Opens the VBA online Help window.

F1

Help, Microsoft Visual Basic Help


Other tools are available on the three additional toolbars, two of which are shown in Figures 2.2 and 2.3. You'll learn more about the tools on these toolbars as you work through the examples in this book. A fourth toolbar, UserForm, is available, but we won't cover UserForms or the toolbar in this book.

Figure 2.2. Debug tools help you quickly squash bugs in your code.

graphics/02fig02.jpg


Figure 2.3. Use Edit tools to produce efficient code.

graphics/02fig03.gif


NOTE

We won't be using UserForms because Access has its own forms, with which you should already be familiar. Access forms are more powerful and flexible than UserForms. Why, then, do UserForms even exist? The answer is that the VBE, and VBA itself, are shared components. You'll find VBA implemented in dozens of software packages, including other Microsoft Office applications, Autodesk's AutoCAD drawing package, Peachtree Office Accounting, and more. These other products, which lack their own forms interface, benefit from the inclusion of UserForms in VBA.


To display a toolbar, choose View, Toolbars and click the appropriate toolbar item: Debug, Edit, or Standard. (Uncheck an item to hide the toolbar.)

     < 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