Platform SDK: CDO 1.2.1

Delete Method (Field Object)

The Delete method removes the Field object from the Fields collection if the field is user-defined or optional.

Syntax

objField.Delete( )

Remarks

This method only deletes user-defined fields and fields that represent properties considered optional by the underlying provider.

The Delete method performs an irreversible operation on the collection. It calls Release on the collection's reference to the Field object. If you have another reference to the field, you can still access its properties and methods, but you can never again associate it with any collection because the Add method always creates a new object. You should Set your reference variable either to Nothing or to another field.

The final Release on the Field object takes place when you assign your reference variable to Nothing, or when you call Delete if you had no other reference. At this point the object is removed from memory. Attempted access to a released object results in an error return of CdoE_INVALID_OBJECT.

When you delete a member of a collection, the collection is immediately refreshed, meaning that its Count property is reduced by one and its members are reindexed. To access a member following the deleted member, you must use its new index value. For more information, see Looping Through a Collection.

The effect of the Delete operation is not permanent until you use the Update, Send, or Delete method on the parent AddressEntry, AddressEntryFilter, AddressList, AppointmentItem, Attachment, Folder, InfoStore, MeetingItem, Message, or MessageFilter object of the Fields collection.

Example

This code fragment illustrates the two situations previously explained. The Set statement calls AddRef on the first Field object. That reference survives the call to Delete and has to be reassigned. The second Field object is deleted without creating another reference, and no other action is necessary.

' assume valid Message object 
Set objField = objMessage.Fields.Item(1) 
objField.Delete ' still have a reference from Set statement 
' ... other operations on objField possible but pointless ... 
Set objField = Nothing ' necessary to remove reference 
' ... 
objMessage.Fields.Item(2).Delete ' no reference to remove