ViewFields.Add Method
Outlook Developer Reference |
Adds the specified field to the end of the ViewFields collection for the view.
Version Information
Version Added: Outlook 2007
Syntax
expression.Add(PropertyName)
expression A variable that represents a ViewFields object.
Parameters
Name | Required/Optional | Data Type | Description |
---|---|---|---|
PropertyName | Required | String | The name of the property to which the new object is associated. This property can be referenced by field name (displayed in the Field Chooser) or by namespace (represented by ViewField.ViewXMLSchemaName). |
Return Value
A ViewField object that represents the new view field.
Remarks
Referencing the property in
PropertyName
by its field name requires the localized name in the corresponding locale. For more information on referencing properties by namespace, see Referencing Properties by Namespace.
If you are adding a custom property to the ViewFields collection, the property must exist in the UserDefinedProperties collection for the View’s parent folder.
If the property already exists in the ViewFields collection, Outlook will raise an error.
Certain properties cannot be added to a view using ViewFields.Add, including binary properties, computed properties, and HTML or RTF body content. For more information, see Unsupported Properties in a Table Object or Table Filter.
Example
The following code sample in Microsoft Visual Basic for Applications (VBA) adds the Subject field to the current view of the Inbox, referencing it by its field name. To avoid Outlook raising an error, it tests for the presence of the field in the ViewFields collection representing the current view of the Inbox before adding it.
Visual Basic for Applications |
---|
|
The following code sample in VBA assumes the current view is a TableView, references the Message Class property by namespace and adds it to the current view of the current folder. To avoid Outlook raising an error, the code checks for the existence of this property in the view before calling ViewFields.Add.
Visual Basic for Applications |
---|
|
See Also