PropertyAccessor.SetProperties (Outlook)

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

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:

SetProperties (SchemaNames, Values)


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

Arguments

The following arguments are required:

SchemaNames (String) - 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 - An array of values that are to be set for the properties specified by the SchemaNames parameter