Previous Document Next Document
DataItems.Add

Function Add(DataField As DataField, [Value As Variant]) As DataItem

Member of DataItems

The Add method adds a new data field to a shape and optionally sets its value.

If a data field is not a document default and is empty for the current shape, it is not listed in the shape’s DataItems collection — that is, it is not returned by the ObjectData property. In this case, the Add method is the only way to set some value to that field. If the field is already listed in the collection, the Add method returns the reference to its data item.

Parameters
Description
DataField
Identifies the data field. A data field is a single property or value associated with a data item object.
Value
Associates a value for the new data field
This parameter is optional.

The following code example adds a new data field with name Weight to the active shape and sets its value to 6. The Weight field must already be defined in the current document.

Sub Test() 
 Dim df As DataField 
 Dim di As DataItem 
 Set df = ActiveDocument.DataFields.Add("Weight1") 
 Set di = ActiveShape.ObjectData.Add(df) 
 di.Value = 6 
End Sub 
The following code example adds a data field and sets its value to 10. 
Sub Test() 
 Dim df As DataField 
 Dim di As DataItem 
 Set df = ActiveDocument.DataFields.Add("Weight2") 
 Set di = ActiveShape.ObjectData.Add(df, 10) 
 MsgBox "The new value of '" & df.Name & "' field is " & 
di.FormattedValue 
End Sub 

Previous Document Next Document Back to Top

Copyright 2007 Corel Corporation. All rights reserved.