The Form-Based Development Environment

Although this chapter will discuss attaching code to Outlook forms, rather than creating and modifying Outlook forms themselves, we'll begin by looking at how the Outlook object model views the Outlook user interface and by briefly examining how you access and work with Outlook forms in design mode; both topics provide background that is necessary in order to begin coding. Then we'll look at Outlook's rather primitive VBScript environment.

6.2.1 Interfaces and Objects

Figure 6-1 shows a more-or-less standard Outlook window with Outlook displaying a mail folder. The Outlook window is divided into three parts, which correspond to four elements of the Outlook object model.

Figure 6-1. The Microsoft Outlook interface


The Folder List

On the left of the Outlook window is the Folder List. In the Outlook object model, this corresponds to the NameSpace object, which has a Folders collection in which each Folder object represents a folder in the MAPI store.

The Explorer

On the upper right of the Outlook window is theExplorer pane. (The term "Explorer" here is unrelated to Windows Explorer, the utility for displaying the Windows namespace and filesystem.) The Explorer pane is responsible for listing the items in the current folder. Each type of item has its ownExplorer object, which is a member of the Explorers collection.

The Inspector

On the lower right of the Outlook window is thePreview pane. In other cases, when the entire right side of the Outlook window is occupied by the Explorer pane, the Preview pane appears when the user selects an item in the Explorer pane. The Preview pane is responsible for displaying the item selected in the Explorer pane and corresponds to anInspector object in the Outlook object model. Note that the Inspector object uses an Outlook form to present a particular view of an Outlook data item.

An item

An item is one of several different object types that hold information. Outlook items include mail messages, appointments, and contacts. In the Outlook object model, these correspond to objects of specific kinds. For instance, a mail message is represented by a MailItem object, while an appointment is represented by an AppointmentItem object and a contact is represented by a ContactItem object. Table 6-1 lists the items available in Outlook and their corresponding objects in the Outlook object model.

Table 6-1. Outlook items and their objects

Item type

Outlook object


AppointmentItem object


ContactItem object

distribution list

DistListItem object


DocumentItem object

journal entry

JournalItem object

mail message

MailItem object

mail nondelivery report

ReportItem object


MeetingItem object


NoteItem object


PostItem object

remote mail message

RemoteItem object


TaskItem object

task acceptance notification

TaskRequestAcceptItem object

task rejection notification

TaskRequestDeclineItem object

task assignment request

TaskRequestItem object

task assignment update

TaskRequestUpdateItem object

With this basic (and frequently nonintuitive) terminology out of the way, we return to the discussion of accessing the environment for developing Outlook forms.

6.2.2 Outlook Form Design Mode

Outlook requires that a form be in design mode rather than in run (or display) mode before you can attach code to it. You can select the form that you'd like to program and open it in run mode in any of the following ways:

  • Select File figs/u2192.gif New from Outlook's main menu and choose the form type you'd like to create, modify, or code from the available menu items (Mail Message, Appointment, etc.).
  • Select File figs/u2192.gif New figs/u2192.gif Choose Form from Outlook's main menu. Outlook opens the Choose Form dialog, which allows you to select an existing form.
  • Select Tools figs/u2192.gif Forms figs/u2192.gif Choose Form from Outlook's main menu. Outlook opens the Choose Form dialog, which allows you to select an existing form.

You can then place the form in design mode by selecting Tools figs/u2192.gif Forms figs/u2192.gif Design This Form from the form's menu.

You can also open a form and place it in design mode in either of the following ways:

  • Select Tools figs/u2192.gif Forms figs/u2192.gif Design a Form from Outlook's main menu. Outlook opens the Design Form dialog, which allows you to select the form you'd like to open. Outlook then opens the form you select in design mode.
  • Select Tools figs/u2192.gif Forms figs/u2192.gif Design a Form from the menu of an Outlook form either when it is in design mode or in run mode. Outlook opens the Design Form dialog, which prompts you for the form you'd like to open. Outlook then opens the form in design mode.

Since Outlook's form-based development environment is somewhat idiosyncratic, let's review some of the basics of working with Outlook forms:

  • You can't create a new Outlook form directly. To create a new form, you have to open an existing form, modify it, and save it as a new form.
  • You can modify an existing form by simply overwriting it. However, Outlook won't permit you to overwrite forms in the Standard Forms Library, where Outlook stores its "hardcoded" forms.
  • You can create or modify any type of Outlook form except for a note. Notes cannot be customized, nor are they programmable, presumably because of their extreme simplicity.
  • You don't "save" a form that you've modified or created. Instead, you "publish" it by clicking on the Publish Form button on the item's toolbar or by selecting the Tools figs/u2192.gif Forms figs/u2192.gif Publish Form or Tools figs/u2192.gif Form figs/u2192.gif Publish Form As option from the item's menu.
  • You can retrieve forms from and save forms to a variety of locations:

    The Standard Forms library

    These are the "out of the box" forms provided by Outlook. The library is read-only; if you modify its forms, you have to save them elsewhere.

    The Personal Forms library

    These are customized forms stored in the current user's personal store (.pst) file. As a result, they are inaccessible to other users.

    The Organizational Forms library

    For organizations using Microsoft Exchange, these forms are stored on the server and are accessible to all Outlook users with access to the server and with the necessary permissions. The library is unavailable for Outlook clients not using Microsoft Exchange.

    An Outlook folder

    Forms stored in Outlook folders are accessible only in that folder. If the folder is a public one, then the form is available to all users with access to the folder. Otherwise, the form is stored in the user's .pst file and is accessible only to him.

  • Outlook forms use the controls found in the MS Forms librarythe same set of controls used in Microsoft Office UserForms. The controls are displayed on the control toolbox, which becomes visible when you click on the Control Toolbox button on a form's toolbar, or when you select Form figs/u2192.gif Control Toolbox from a form's menu.
  • Just as in Visual Basic and in the VBA-hosted environments, you work with controls by setting their properties. The standard properties sheet is displayed when you select Form figs/u2192.gif Advanced Properties from the form's menu. A more user-friendly Properties dialog is displayed when you select Form figs/u2192.gif Properties from the form's menu.
  • You can choose the data fields that your form displays by selecting them from the Field Chooser. The Field Chooser can be made visible by clicking on the Field Chooser button on the form's toolbar or by selecting the Form figs/u2192.gif Field Chooser option from the form's menu.

6.2.3 The VBScript Environment

To write code for your form, open the VBScript editor by clicking on the View Code button on the form's toolbar or select the View Code option from the form's Form menu. Outlook will open the VBScript editor, which is shown in Figure 6-2.

Figure 6-2. The VBScript editor


If you're familiar with the rich development environments of Visual Basic or the hosted versions of VBA, you'll recognize the VBScript editor as an extremely poor cousin. In fact, the editor is distinctly Notepad-like, without any of the amenities of the VBA IDE. Syntax is not checked automatically, nor are auto list members, auto quick info, or auto data tips available. In fact, the editor does not even have an option that allows you to require variable declaration. This feature, which is available in the VB and VBA IDEs, automatically adds an Option Explicit statement to each code module.

In keeping with its minimalist approach, the VBScript editor offers an object browser, though it lacks most of the ease-of-use features of the Object Browser found in the VBA IDE. To open it, select Script figs/u2192.gif Object Browser from the VBScript Editor's menu. The VBScript object browser is shown in Figure 6-3. It lacks the icons that help identify elements in the VBA Object Browser. (For instance, the entries that begin "Ol" in the Classes list box are enumerations; casual inspection might lead you to completely overlook that fact.) Nor is the VBScript object browser searchable, which is a serious limitation. Finally, in the case of form-level events (which the object browser depicts as members of the ItemEvents object), the prototypes displayed by the object browser in the status bar are not completely consistent with the shells that the editor creates for them. For experienced programmers, this discrepancy will most probably go unnoticed. For inexperienced programmers, it serves as another source of needless confusion.

Figure 6-3. The VBScript object browser


If you need to browse the Outlook object model while you're programming, it's best to use the VBA Object Browser. It's available by opening the VBA IDE (select Tools figs/u2192.gif Macro figs/u2192.gif Visual Basic Editor from the Outlook menu) and pressing F2.

Part I: The Basics


Program Structure

Data Types and Variables

Error Handling and Debugging

VBScript with Active Server Pages

Programming Outlook Forms

Windows Script Host 5.6

VBScript with Internet Explorer

Windows Script Components

Part II: Reference

Part III: Appendixes

Appendix A. Language Elements by Category

Appendix B. VBScript Constants

Appendix C. Operators

Appendix E. The Script Encoder

Vbscript in a Nutshell
VBScript in a Nutshell, 2nd Edition
ISBN: 0596004885
EAN: 2147483647
Year: 2003
Pages: 335 © 2008-2020.
If you may any questions please contact us: