![]() |
![]() |
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 shapes 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.
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
![]() |
![]() |
![]() |
Copyright 2007 Corel Corporation. All rights reserved.