Sets the property specified by
SchemaName | to the value specified by
Value | .
Version Information
Version Added: Outlook 2007
Syntax
expression.SetProperty(SchemaName, Value)
expression A variable that represents a PropertyAccessor object.
Parameters
| Name | Required/Optional | Data Type | Description |
|---|
| SchemaName | Required | String | The name of a property whose value is to be set as specified by Value . The property is referenced by namespace. For more information, see Referencing Properties by Namespace. |
| Value | Required | Variant | The value that is to be set for the property specified by SchemaName . |
Remarks
If the property does not exist and the
SchemaName | contains a valid property specifier, then
SetProperty creates the property and assigns the value specified by
Value | . If the property does exist and
SchemaName | is valid, then
SetProperty assigns the property with the value specified by
Value | .
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.
For more information on setting properties using the PropertyAccessor object, see Best Practices for Getting and Setting Properties.
Example
The following code sample shows how to use the PropertyAccessor to set a custom property on a MailItem object to a value. If the custom property does not exist, PropertyAccessor.SetProperty will create and then set the property. The property is saved with the MailItem.Save method.
| Visual Basic for Applications |
|---|
Sub DemoPropertyAccessorSetProperty()
Dim myProp As String
Dim myValue As Variant
Dim oMail As Outlook.MailItem
Dim oPA As Outlook.PropertyAccessor
'Get first item in the inbox
Set oMail = _
Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
'Name for custom property using the MAPI string namespace
myProp = "http://schemas.microsoft.com/mapi/string/" & _
"{FFF40745-D92F-4C11-9E14-92701F001EB3}/myCustomer"
myValue = "Dan Wilson"
'Set value with SetProperty call
'If the property does not exist, then SetProperty
'adds the property to the object when saved.
'The type of the property is the type of the element
'passed in myValue.
On Error GoTo ErrTrap
Set oPA = oMail.PropertyAccessor
oPA.SetProperty myProp, myValue
'Save the item
oMail.Save
Exit Sub
ErrTrap:
Debug.Print Err.Number, Err.Description
End Sub
|