Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/161924

From BetaArchive Wiki

Article ID: 161924

Article Last Modified on 2/12/2007


  • Microsoft Outlook 97 Standard Edition

This article was previously published under Q161924


You can customize Microsoft Outlook forms by using Microsoft Visual Basic Script and\or ActiveX controls. This article illustrates how to add Outlook form controls and VBScript to an Outlook form. The example in this article uses the TextBox and CheckBox controls, and with VBScript programmatically populates those controls when you open the form.


Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:

Customizing the Form and Adding Controls

The following steps demonstrate how to customize a message form by making a new page visible and adding a TextBox and CheckBox control on the new page:

  1. In Outlook open a new message. On the Form Design toolbar, click "Design Outlook Form."
  2. Click the (P.2) tab to select the second page of the form. On the Form menu, click Form and then click "Display This Page." This will remove the parentheses from around P2 and make the P2 page viewable when the form is done.
  3. On the Form Design toolbar, click "Control Toolbox" and on the Controls tab click the TextBox control. Drag a TextBox onto the form. Repeat the process to place a CheckBox on the form.

Binding a Field to Each Control

While you can manipulate the appearance of a control (color, font, etc.) with Advanced Properties, you must use a field to manipulate the value of a control (Is the CheckBox checked? What text appears inside the TextBox?).

The following steps bind custom fields to each control. In this case TextBoxField is the name of the field bound to the TextBox control. CheckBoxField is the name of the field bound to the CheckBox control.

  1. On the form, right-click the TextBox and on the shortcut menu, click Properties.
  2. Under the Value tab, click New.
  3. In the Name box, type TextBoxField. By default, the Type and Format lists should display Text.
  4. Click OK and OK to close the Properties dialog box for the TextBox control.
  5. On the form, right-click the CheckBox and on the shortcut menu, click Properties.
  6. Under the Value tab, click New.
  7. In the Name box, type CheckBoxField. In the Type list, click Yes/No. In the Format list, click True/False.
  8. Click OK and OK to close the Properties dialog box for the CheckBox control.

Adding VBScript to Populate the Controls

The following steps programmatically change each control when the form opens by changing the value of the fields to which each control is bound. The value of TextBoxField changes to: "New text." The value of CheckBoxField changes to True. Therefore, the CheckBox appears checked.

  1. On the Form Design toolbar, click View Code to start the Script Editor. On the Script menu, click Event and click to select Open in the Events list and then click Add.
  2. Type the following code between "Function Item_Open()" and "End Function":

         Set MyTextBoxField = Item.UserProperties.Find("TextBoxField")
         If MyTextBoxField.Value = "" Then MyTextBoxField.Value = "New text"
         End If
         Set MyCheckBoxField = Item.UserProperties.Find("CheckBoxField")
         If MyCheckBoxField.Value = 0 Then MyCheckBoxField.Value = 1
         End If

    NOTE: The names used in quotation marks are the names of the fields which you bound to each control. The value assigned to the TextBoxField field determines what appears inside the TextBox control. The value assigned to the CheckBoxField field determines if the CheckBox control has a check.

  3. On the Script Editor's File menu, click Close.

Exiting the Form Design Mode and Publishing the Form

Because the programming code in this example is in the Item_Open function, it executes when you open the form. You should publish the form so that you can see the results when you open a new form.

You can publish forms several ways. This example shows how to publish your form in your Inbox folder. Follow these steps to exit the design mode and publish the form:

  1. On the form's Tools menu, click "Design Outlook Form" to exit the design mode.
  2. On the form's File menu, click "Publish Form As."
  3. In the "Form name" box, type MyForm and click "Publish In."
  4. In the "Set Library To" dialog box, click "Folder Forms Library."
  5. In the folder list, click to select your Inbox folder and click OK.
  6. Click Publish to publish MyFrom in your Inbox folder.
  7. On the form's File menu, click Close. When prompted, "Do you want to save changes?" click No.

Using the Form

You published the form in your Inbox folder, so you must open your Inbox to use the form. Follow these steps to use the form:

  1. Open your Inbox.
  2. On the Compose menu, click "New MyForm" to open an untitled message based on your custom form.
  3. Inside the form, click the P.2 tab.

Note: if you do not see a P.2 tab, you skipped step 2 in the section titled, "Customizing the Form and Adding Controls."

The TextBox should contain the text "New text" and the CheckBox should contain a check.


For more information about creating solutions with Microsoft Outlook 97, please see the following articles in the Microsoft Knowledge Base:

166368 OL97: How to Get Help Programming with Outlook

170783 OL97: Q&A: Questions about Customizing or Programming Outlook

Additional query words: OutSol OutSol97

Keywords: kbcode kbhowto kbprogramming KB161924