Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
OL98: How to Use Fields and Controls with VBScript
Article ID: 182362 - View products that this article applies to.
This article was previously published under Q182362
When you write Visual Basic Scripting Edition (VBScript) code to customize a Microsoft Outlook 98 form, you must understand the relationship between the item's fields and form controls.
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 a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:
Microsoft Certified Partners - https://partner.microsoft.com/global/30000104
Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS
The Difference Between Controls and FieldsControls are objects, such as a text box, a scroll bar, a rectangle, a list box, or a command button, that let users control the program. You place controls on a form to display data or choices, perform an action, or make the form easier to read. As an example, you can control a mail message item by using built-in controls, such as the "Subject" textbox, or you can modify the form by adding your own controls. Controls, by themselves, provide no storage for the data that is associated with them. Controls are only the visual representation of the data on the form.
Item fields are the actual Messaging Application Programming Interface (MAPI) properties where you store data when you save or send an item. In the example above, the "Subject" listbox control is linked (or "bound") to an item field also called "Subject." The control and the field may or may not have the same name.
Using Fields and ControlsAll of the built-in form controls (To, From, Cc, and such) are automatically linked to corresponding built-in MAPI fields. However, if you create a custom form and add a custom control, you should typically create a MAPI field to store the data that is associated with the control.
For example, suppose you want to add a textbox to your mail message form that may enable people to type in their office location. When you design the new form, you can add a textbox control by dragging the control from a special toolbar called the Control Toolbox. This creates a place to type in the office location. Since the control itself provides no storage for the item, when you send the item to someone, the text you typed into the office location is lost. You must also create a field to provide storage for the data.
You can create a field by using the Field Chooser. Once the field is created, you then use the Properties dialog of the office location textbox control to bind the control to the field. Once this is done, the office location control has an item field to provide storage for the data. This way, when someone fills in the field and sends the item, the data is preserved when the item is received by someone else.
Steps to Create a Control on a Form
Steps to Create a Field to Provide Storage for the Control
Steps to Bind a Control to a Field
Using VBScript to Change Field and Control ValuesThe VBScript syntax for accessing values associated with controls is quite different from the syntax for accessing fields. There are situations where it is possible to change a value by using either method.
Syntax for Accessing a Control on a Form
Generic: Item.GetInspector.ModifiedFormPages("PageName").Controls _ ("ControlName").Property = <value> Example: Item.GetInspector.ModifiedFormPages("Message") _ .Controls("OfficeLoc").Visible = True
Syntax for Accessing a Built-in Field
Generic: Item.FieldName = <Value> Example: Item.Subject = "This is a new subject"
Syntax for Accessing a Field You Create (User-defined Field)
Generic: Item.UserProperties.Find("FieldName").Property = Value Example: Item.UserProperties.Find("OfficeLoc").Value = "Blg 4, 1234"
In the "Office Location" example above, these two example lines of code have the same effect on the form.
The first example changes the Office Location field to a new value, and the second line changes the textbox control text property to the new value. Since the control is bound to the field, a change made in either place affects the other.
Tips for When to Use Each Method
For more information on fields and controls, please see the following Articles in the Microsoft Knowledge Base:
182365For more information about creating solutions with Microsoft Outlook 98, please see the following articles in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/182365/EN-US/ )OL98: How to Programmatically Set TextBox and CheckBox Values
(http://support.microsoft.com/kb/180911/EN-US/ )OL98: How to Populate a ComboBox With Your Contacts (VBScript)
(http://support.microsoft.com/kb/180826/EN-US/ )OL98: Resources for Custom Forms and Programming
(http://support.microsoft.com/kb/182349/EN-US/ )OL98: Questions About Custom Forms and Outlook Solutions
Article ID: 182362 - Last Review: February 26, 2004 - Revision: 1.2