Delete Method (AddressEntry Object)

Delete Method (AddressEntry Object)

The Delete method removes the AddressEntry object from the AddressEntries collection.


objAddressEntry.Delete( )


The Delete method performs an irreversible operation on the collection. It calls Release on the collection's reference to the AddressEntry object. If you have another reference to the address entry, 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 address entry.

The final Release on the AddressEntry 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.

The action of the Delete method is permanent, and the AddressEntry object cannot be restored to the collection. Before calling Delete, your application can prompt the user to verify whether the address entry should be permanently deleted.

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 user must have the appropriate permission to Add, Delete, or Update an AddressEntry object. Most users have this permission only for their personal address book (PAB).

The CDO Library does not support addition, deletion, or modification of members of a distribution list (DL) on the global address list (GAL).

You can delete all the address entries in the AddressEntries collection by calling the collection's Delete method. The ability to delete any address entry depends on the permissions granted to the user. The Delete method returns an error code if called with insufficient permissions.


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

' assume valid AddressList object
Set objAddressEntry = objAddressList.AddressEntries.Item(1)
objAddressEntry.Delete ' still have a reference from Set statement
' ... other operations on objAddressEntry possible but pointless ...
Set objAddressEntry = Nothing ' necessary to remove reference
' ...
objAddressList.AddressEntries.Item(2).Delete ' no reference to remove

See Also


AddressEntry Object