Platform SDK: CDO 1.2.1

Categories Property (Message Object)

The Categories property specifies the categories assigned to the message. Read/write.

Syntax

objMessage.Categories

Data Type

String array

Remarks

The contents of the Categories property are defined by the application. Categories is commonly used to hold a set of keywords that can be used to access messages in a folder.

AppointmentItem objects in a Microsoft® Schedule+ calendar folder do not have the full set of attributes of a general message. If you obtain the default calendar folder by passing CdoDefaultFolderCalendar to the Session object's GetDefaultFolder method, its appointments have no defined value for the Categories property. An attempt to access Categories in this case returns CdoE_NO_SUPPORT.

When you declare a variable to interact with the Categories property, you must Dim it appropriately, not just as an array of unspecified data type. To copy the variable to Categories, declare it as a String array:

   Dim KWords (10) As String ' NOT just Dim KWords (10) 
   ' ... 
   objMessage.Categories = KWords ' accepts string array 
 

To copy Categories to a variable, declare the variable as a Variant array:

   Dim Keys (10) As Variant ' NOT Dim Keys (10) or Dim As String 
   ' ... 
   Keys = objMessage.Categories ' returns variant array 
 

This is because Categories accepts arrays of various data types but always returns a Variant array.

Note  When you access an element of the Categories array, whether to read it or write it, you must include an extra set of parentheses to satisfy the Visual Basic compiler's allowance for a property parameter:

   objMessage.Categories()(3) = "Third category" 
   ' ... 
   Kwords(i) = objMessage.Categories()(i) 
 

For more information on property parameters, see Property Parameters.

Example

This code fragment sets the Categories property of a message from a string array of keywords and later displays the categories:

Dim objMessage As Message 
' assume objMessage is valid and already being accessed 
Dim KWords (10) As Variant ' NOT As String or just Dim KWords(10) 
' ... obtain up to ten keywords from user ... 
objMessage.Categories = KWords ' whole array; no index or parameter 
' ... later, read the message and examine its properties ... 
MsgBox "Categories for this message are:" 
For i = LBound(objMessage.Categories) To UBound(objMessage.Categories) 
  If 0 < Len(objMessage.Categories()(i)) Then 
    MsgBox vbCrLf & objMessage.Categories()(i) 
  End If 
Next i