Add Method (Views Collection)

The Add method creates and returns a new CalendarView or TableView object in the Views collection.

Syntax

Set objView = objViewsColl.Add(bstrName [, varClass] [, varSortBy] [, varSortAscending] )

objView
On successful return, contains the new CalendarView or TableView object.
objViewsColl
Required. The Views collection object.
bstrName
Required. String. The display name to be assigned to the new CalendarView or TableView object.
varClass
Optional. Long. The class of the view to be created. The currently supported classes are CdoClassCalendarView and CdoClassTableView. The default value is CdoClassTableView.
varSortBy
Optional. Variant (Long or String). The property on which to sort the new view. The default value is CdoPR_MESSAGE_DELIVERY_TIME if a corresponding column is present in the view. If no such column is present and the varSortBy parameter is not furnished, there is no default value and the sort is undefined.
varSortAscending
Optional. Boolean. The sort direction of the new view. Set to True to sort in ascending order. The default value is False.

Remarks

The Add method's bstrName parameter corresponds to the Name property of the new CalendarView or the Name property of the new TableView object. The varClass parameter corresponds to the new view's Class property.

The calendar view's Name property and the table view's Name property are both read-only. After you set the display name of a new view, you cannot subsequently change it.

You should give every view object a unique name. CDO does not enforce uniqueness, but if a collection has duplicate names, only the first one can be found by name.

The varSortBy parameter must designate a property represented by a Column object within the new view's Columns collection. varSortBy must contain the property tag of the desired property. If you wish to sort the view on a custom property, you can obtain its property tag from the ID property of the Field object being used to access the custom property:

An address book container does not have any common, personal, or folder views predefined. If you are rendering an address book container, you must define one or more custom views for it. Furthermore, you must Add any new custom views to the present Views collection before you set the ContainerRenderer object's DataSource property to an AddressEntries collection. Otherwise the new custom views are not handled properly in the rendering.

Example

This code fragment creates a custom table view to sort the messages in the Inbox folder according to their index values in the Inbox Messages collection. A new field must be created and set to each message's index value, because Message objects do not expose an Index property. Then the ID property of the new field is used to specify the sort property for the new view. Finally, a corresponding column is added to the view's Columns collection using its Add method. This is necessary because the sort property must be represented by a Column object in the view. The new column cannot be added until after the new view has been created, but the column criterion for the varSortBy parameter is considered satisfied as long as the column is added before the view is rendered.

   ' assume Session and ContainerRenderer already valid 
   Dim colMsgs As Messages ' Inbox collection 
   Dim objMsg As Message 
   Dim colFields As Fields ' Message object fields 
   Dim objMsgIx As Field ' custom field for message index 
   Dim index As Long ' index of each message in Inbox collection 
   Dim tagMsgIx As Long ' property tag of custom message index field 
   Dim objIxView As TableView ' new table view sorted on index value 
' 
   Set colMsgs = objSess.Inbox.Messages 
   objContRend.DataSource = colMsgs ' render Inbox Messages collection 
   index = 0 
   For Each objMsg in colMsgs 
   index = index + 1 
      Set colFields = objMsg.Fields 
      ' data type vbLong has decimal value 3: 
      Set objMsgIx = colFields.Add ("Message index", 3, index) 
      objMsg.Update ' save new field in this message 
   Next 
   tagMsgIx = colFields.Item(objMsgIx.Index).ID 
   ' class CdoTableview has decimal value 9: 
   Set objIxView = objContRend.Views.Add _ 
                            "Table view on message index", 9, tagMsgIx 
   objIxView.Columns.Add "Index", tagMsgIx, 3, 0, 0, 3