This article describes how Microsoft Outlook implements the Message orNotes field and answers some common questions regarding its use when youcustomize Outlook forms.
This article discusses using fields and controls with Outlook forms. It is important to understand the difference between the two. For additional information about the differences between fields and controls, click the article number below to view the article in the Microsoft Knowledge Base:
OL2002: Overview of Using Fields and Controls on Custom Forms
Working with the Message or Notes Field
The Message field is most commonly associated with a mail message form andis the main portion or "body" of the message. This is a unique fieldbecause it supports text in multiple formats, such as Rich Text Formatting(RTF), HTML, and Plain Text. You can also embed objects such as shortcuts or files into the message field.
This field also exists on other Outlook forms. On a Post form, it is calledthe Message field, but on all other forms, it is referred to as the Notesfield. When you access this field through the Outlook object model, it isalways referred to as the Body property of the appropriate item(ContactItem, PostItem, and such).
The following table summarizes the naming conventions:
Item Type Field Name Property Name --------- ---------- ------------- Mail message Message Body Post Message Body Contact Notes Body Appointment Notes Body Meeting Request Notes Body Task Notes Body Task Request Notes Body Journal Notes Body Note* N/A Body * You cannot customize "Note" items. NOTE
: The remainder of this article will use the term "Message field" to refer to both Message and Notes.
Each Outlook item contains one Message field, and it is not possible to addan additional field of the same type as the Message field.
Working with the Message or Notes Control
When you design an Outlook form, you can use the Message control more thanonce on a form. However, when you insert a second Message control on aform, Outlook displays the following warning:
This form has more than one Message or Notes control. If more than one control is visible at run time, only one control works.
This warning may also appear when you use the form, such as when youswitch to a form page that contains a second Message control.
Outlook controls are typically bound to MAPI fields to store the actualdata. Each Outlook form or item has only one field that supports "richtext." Therefore, when you drag the Message field from the Field Chooseronto the form, it is automatically bound to the appropriate Outlook field.You cannot change this behavior. If there is more than one Message field ona form, they will all display the same data since there is only one fieldof this type permitted for each Outlook form. If you change data in one ofthe Message fields it does not automatically replicate to the other Messagefield unless you refresh the field by saving and reopening the form orsetting the Body property via code.
The control used to display the Message field is built into the Outlookprogram and is not designed for use on non-Outlook forms. However, you canadd the control to the Control Toolbox since it is a registered control onthe system. Use your right mouse button to click a blank area of theControl Toolbox, and from the shortcut menu, click Custom Controls."Outlook DocSite OLE Control" should be in the list of availablecontrols. This is the control that is used to display the Message field.
Working with the Body Property with All Types of Message Formats
The Outlook user interface allows you to apply various formatting to mailmessages, but when you use the Body property from Microsoft Visual BasicScripting Edition (VBScript) or Microsoft Visual Basic for Applications, all of the text formatting is lost. This is because in the Outlook object model, the data type of the Body property is text, so it behaves no differently than other types of controls, such as a label or text box.
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
When you use VBScript, you cannot programmatically insert information intothe body of an Outlook item without completely replacing the body. The Bodyproperty enables you to programmatically create and delete the body text,but it does not enable you to insert or modify information that is withinthe body.
For example, you may have a mail item with the following text in theMessage field:
------------------------------- Thank you for using: We appreciate your business. -------------------------------
If you want to programmatically insert a product name between the lines,there is no method or property available that will not completely replaceall of the body, as shown in the following examples.
' Completely replaces the existing text in the body. Item.Body = "This is new text" ' Completely deletes the text in the Body. Item.Body = ""
The following VBScript example enables you to insert text within the Bodyproperty of the previous example. It does so by parsing the existing text and re-inserting new body text.
Sub Item_Open() ' Dimension X1, X2 to hold the return of the InStr function. Dim X1, X2 ' Get the location of the first carriage return. X1 = Instr(1, Item.Body, Chr(13), 1) ' Get the location of the second carriage return. X2 = Instr(X1 + 1, Item.Body, Chr(13), 1) ' Get the text from the beginning of the body to the second carriage ' return. TempA = Left(Item.Body, X2) ' Get the rest of the text. TempB = Mid(Item.Body, X2 + 1, Len(Item.Body)) ' Create new text. NewText = "Gadget Company" & Chr(13) ' Insert new Body which includes new text. Item.Body = TempA & NewText & TempBEnd Sub
If you are using an HTML mail message, you can use the Outlook objectmodel to access the HTML Document Object Model and use that object model tomanipulate the embedded HTML. For more information, see the HTMLEditorproperty in the Microsoft Outlook Visual Basic Reference (Vbaol10.chm).NOTE
: For security reasons, you cannot use scripting code from within an HTML-based mail message to access the Outlook object model.
If you are using a WordMail message, you can use the WordEditorproperty to return the Microsoft Word object model and then use the objectmodel to change the embedded Word document object. For more information,see the WordEditor property in the Microsoft Outlook Visual Basic Reference(Vbaol10.chm).
Programmatically Changing the Editor Type
The Outlook 2002 object model allows you to programmatically change the editor that is used for the body of an item. For more information,see the BodyFormat property in the Microsoft Outlook Visual Basic Reference(Vbaol10.chm).