Share via


PropertyAccessor Object (Outlook)

Provides the ability to create, get, set, and delete properties on objects.

Version Information

Version Added: Outlook 2007

Remarks

Use the PropertyAccessor object to get and set item-level properties that are not explicitly exposed in the Outlook object model, or properties for the following non-item objects: AddressEntry, AddressList, Attachment, ExchangeDistributionList, ExchangeUser, Folder, Recipient, and Store.

To get or set multiple custom properties, use the PropertyAccessor object instead of the UserProperties object for better performance.

For more information on using the PropertyAccessor object, see Properties Overview.

Example

The following code sample demonstrates how to use the PropertyAccessor.GetProperty method to read a MAPI property that belongs to a MailItem but that is not exposed in the Outlook object model, PR_TRANSPORT_MESSAGE_HEADERS.

Sub DemoPropertyAccessorGetProperty() 
 
 Dim PropName, Header As String 
 
 Dim oMail As Object 
 
 Dim oPA As Outlook.PropertyAccessor 
 
 'Get first item in the inbox 
 
 Set oMail = _ 
 
 Application.Session.GetDefaultFolder(olFolderInbox).Items(1) 
 
 'PR_TRANSPORT_MESSAGE_HEADERS 
 
 PropName = "https://schemas.microsoft.com/mapi/proptag/0x007D001E" 
 
 'Obtain an instance of PropertyAccessor class 
 
 Set oPA = oMail.PropertyAccessor 
 
 'Call GetProperty 
 
 Header = oPA.GetProperty(PropName) 
 
 Debug.Print (Header) 
 
End Sub

The next code sample demonstrates how the PropertyAccessor.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. If the object supports an explicit Save operation, then the properties are saved to the object when the explicit Save operation is called. If the object does not support an explicit Save operation, then the properties are saved to the object when SetProperties is called.

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 = "https://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mylongprop" 
 
 prop2 = "https://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mystringprop" 
 
 prop3 = "https://schemas.microsoft.com/mapi/string/" & _ 
 
 "{FFF40745-D92F-4C11-9E14-92701F001EB3}/mydateprop" 
 
 prop4 = "https://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

See Also

Concepts

Outlook Object Model Reference

PropertyAccessor Object Members