Export (0) Print
Expand All

PropertyAccessor.SetProperties Method (Outlook)

Sets the properties specified by the array SchemaNames to the values specified by the array Values.

Version Added: Outlook 2007

expression .SetProperties(SchemaNames, Values)

expression A variable that represents a PropertyAccessor object.

Parameters

Name

Required/Optional

Data Type

Description

SchemaNames

Required

Variant

An array of names of properties whose values are to be set as specified by the Values parameter. These properties are referenced by namespace. For more information, see Referencing Properties by Namespace.

Values

Required

Variant

An array of values that are to be set for the properties specified by the SchemaNames parameter.

Return Value

A Variant that is Null (Nothing in VBA) if the operation is successful. If there is an error before any properties are set, for example, the number of elements in the SchemaNames array does not match that in the Values array, and an Err value will be returned. If there is an error during the setting of the properties, the return value is an array of Err objects, with the number of elements in this array being the same as that of the SchemaNames array. An Err value in the array is mapped to the error result of setting the corresponding property in the SchemaNames parameter.

If the property does not exist and the SchemaNames element contains a valid property specifier, then SetProperties creates the property and assigns the property with the value specified by Values. The type of the property will be the type of the element passed in Values. If the property does exist, then SetProperties assigns the property the value as specified by Values.

Note that a custom property created by using the PropertyAccessor is not supported in a custom view. If you want to view a custom property on an item, create the property by using the Add method of the UserProperties object.

If the parent object of the PropertyAccessor supports an explicit Save operation, then the properties should be saved to the object with an explicit Save method call. If the object does not support an explicit Save operation, then the properties are saved to the object when SetProperties is called.

Use caution and ensure that all exceptions are handled correctly. Conditions where setting properties fails include:

  • The property is read-only, as some Outlook and MAPI properties are read-only.

  • The property referenced by the specified namespace is not found.

  • The property is specified in an invalid format and cannot be parsed.

  • The property does not exist and cannot be created.

  • The property exists but is passed a value of an incorrect type.

  • Cannot open the property because the client is offline.

  • The property is created using the UserProperties.Add method. When setting the property for the first time, you must use the UserProperty.Value property instead of the SetProperties or SetProperty method of the PropertyAccessor object.

For more information on setting properties using the PropertyAccessor object, see Best Practices for Getting and Setting Properties.

This code sample demonstrates how the SetProperties method sets the values of multiple properties. If a property does not exist, then SetProperties will create the property as long as the parent object supports the creation of those properties. Since the MailItem object supports a MailItem.Save operation, the properties here are saved with an explicit oMail.Save.

Sub DemoPropertyAccessorSetProperties() 
 Dim PropNames(), myValues() As Variant 
 Dim arrErrors As Variant 
 Dim prop1, prop2, prop3, prop4 As String 
 Dim i As Integer 
 Dim oMail As Outlook.MailItem 
 Dim oPA As Outlook.PropertyAccessor 
 'Get first item in the inbox 
 Set oMail = _ 
 Application.Session.GetDefaultFolder(olFolderInbox).Items(1) 
 'Names for properties using the MAPI string namespace 
 prop1 = "http://schemas.microsoft.com/mapi/string/" & _ 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mylongprop" 
 prop2 = "http://schemas.microsoft.com/mapi/string/" & _ 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mystringprop" 
 prop3 = "http://schemas.microsoft.com/mapi/string/" & _ 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mydateprop" 
 prop4 = "http://schemas.microsoft.com/mapi/string/" & _ 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/myboolprop" 
 PropNames = Array(prop1, prop2, prop3, prop4) 
 myValues = Array(1020, "111-222-Kudo", Now(), False) 
 'Set values with SetProperties call 
 'If the properties do not exist, then SetProperties 
 'adds the properties to the object when saved. 
 'The type of the property is the type of the element 
 'passed in myValues array. 
 Set oPA = oMail.PropertyAccessor 
 arrErrors = oPA.SetProperties(PropNames, myValues) 
 If Not (IsEmpty(arrErrors)) Then 
 'Examine the arrErrors array to determine if any 
 'elements contain errors 
 For i = LBound(arrErrors) To UBound(arrErrors) 
 'Examine the type of the element 
 If IsError(arrErrors(i)) Then 
 Debug.Print (CVErr(arrErrors(i))) 
 End If 
 Next 
 End If 
 'Save the item 
 oMail.Save 
End Sub
Show:
© 2014 Microsoft