Article ID: 207430 - Last Review: November 23, 2006 - Revision: 3.2 OL2000: How to Use Fields and Controls with VBScriptThis article was previously published under Q207430 On This PageSUMMARY
This article explains the differences between fields within an Outlook item and controls on an Outlook form. In addition, this article also provides an overview of how to use Visual Basic Scripting Edition (VBScript) to reference fields and controls. NOTE: Programming concepts and syntaxes in this article also apply to programming with Visual Basic for Applications. The only difference is in how you reference the item. MORE INFORMATIONThe Difference Between Fields and ControlsFields (also referred to as properties) actually store data within an Outlook item, such as a contact or a task. The Subject field of a mail message is an example of a field within an item. Fields can be either a pre-defined field that Outlook makes available (such as Subject), or a user-defined field that you can create for your own purposes.Controls are objects, such as a text box, a scroll bar, a list box, or a command button, that let users control, enter, or change data. When designing a custom Outlook form, you place controls on a form to display data or choices, perform an action, or make the form easier to read. Controls by themselves, provide no storage for the data that is associated with them. In the majority of cases, controls are used to display the contents of a field within the item and therefore should be linked, or bound to a particular field. Using Fields and ControlsAll of the pre-defined form controls (To, From, Cc, and such) are automatically bound to corresponding standard Outlook fields. However, if you create a custom form and add a custom control, you should make sure that a field is designated to store the data that is associated with the control.For example, suppose you want to add a text box to your mail message form that enables people to enter their office location. When you design the new form, there are a few ways to accomplish this. The easiest way is to click the New button on the Field Chooser to create the Office Location field. Then you can simply drag the field from the Field Chooser onto the form. Outlook automatically creates a text box on the form and bind it to the Office Location field. You can also add a text box control by dragging the control from the Control Toolbox. This creates the text box on the form to provide a place to enter the office location. Since the control itself provides no storage for the item, the text you typed into the office location is lost when you send the item to someone. You must also bind the control to a 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. To Place a Control on a Form
To Create a Field to Provide Storage for the Control
To Bind a Control to a Field
Using VBScript to Change Field and Control ValuesMicrosoft 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 (https://partner.microsoft.com/global/30000104) Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice (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 (http://support.microsoft.com/default.aspx?scid=fh;en-us;cntactms) The Outlook object model syntax for referencing controls is quite different from the syntax for referencing fields. The following examples use VBScript to illustrate syntax, but the same code examples can be used with Outlook Visual Basic for Applications, or Automation if you make appropriate modifications for referencing the Item or Inspector objects. Syntax for Accessing a Control on a FormSyntax for Accessing a Standard Outlook FieldSyntax for Accessing a User-defined FieldUsage ExamplesIn the "OfficeLoc" example above, these two example lines of code have the same effect on the form.Tips for When to Use Each Method
REFERENCES
For additional information about available resources and answers
to commonly asked questions about Microsoft Outlook 2000 solutions,
please see the following article in the Microsoft Knowledge Base: 146636
(http://support.microsoft.com/kb/146636/EN-US/
)
OL2000: Questions About Custom Forms and Outlook Solutions
| Article Translations
|
Back to the top
