Customizing a Folder or Message

Customizing a Folder or Message

The CDO Library allows customization and extensibility by offering the Field object and Fields collection. A Field object includes a name, a data type, and a value property. An object that supports fields, in effect, lets you add your own custom properties to the object.

The CDO Library supports the use of fields with the AddressEntry, AddressEntryFilter, Attachment, Folder, Message and MessageFilter objects. These objects all have a Fields property through which the Fields collection can be accessed.

For example, suppose that you want to add a “Keyword” property to messages so that you can associate a string with the message. You may wish to use a self-imposed convention that values of the “Keyword” are restricted to a small set of strings. You can then organize your messages by the “Keyword” property.

The following code fragment shows how to add the “Keyword” field to a Message object:

' Function: Fields_Add
' Purpose:  Add a new Field object to the Fields collection
' See documentation topic:  Add method (Fields collection)
Function Fields_Add()
Dim cFields As Integer      ' count of fields in the collection
Dim objNewField As Field    ' new Field object

On Error GoTo error_olemsg
If objFieldsColl Is Nothing Then
    MsgBox "must first select Fields collection"
    Exit Function
End If
Set objNewField = objFieldsColl.Add( _
                  Name:="Keyword", _
                  Class:=vbString, _
                  Value:="Happiness")
If objNewField Is Nothing Then
    MsgBox "could not create new Field object"
    Exit Function
End If
cFields = objFieldsColl.Count
MsgBox "new Fields collection count = " & cFields
' you can now write code that searches for
' messages with this "custom property"
Exit Function

error_olemsg:
MsgBox "Error " & Str(Err) & ": " & Error$(Err)
Resume Next

End Function
 

Note that the new field information specified by the Add method is not actually saved until you call the Message object’s Update method.

MAPI stores all custom properties that represent date and time information using Greenwich Mean Time (GMT). The CDO Library converts these properties so that the values appear to the user in local time.

For more information on the Field object’s data types, see its Type property.

See Also

Creating and Sending a Message

See Also

Concepts

Programming Tasks