Delete Method (Message Object)
Topic Last Modified: 2004-06-09
Optional. Boolean. Indicates whether to move a MeetingItem or Message object to the Deleted Items folder instead of permanently deleting it. The default value is False.
The Delete method performs an irreversible operation on the collection. It calls Release on the collections reference to the AppointmentItem, MeetingItem, or Message object. If you have another reference to the object, 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 object.
The final Release on the AppointmentItem, MeetingItem, or Message 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 Message object cannot be restored to the collection. Before calling Delete, your application can prompt the user to verify whether the message should be permanently deleted.
If you set the DeletedItems parameter to True, Delete moves the MeetingItem or Message object to the Deleted Items folder. DeletedItems is ignored on AppointmentItem objects. To permanently delete an item that is already in the Deleted Items folder, call Delete without supplying DeletedItems.
If the Messages collection underlies a categorized view and the deleted message was the last remaining message in a group, the groups GroupHeader object is also removed from the collection. Unlike the message, however, it is not moved anywhere. Group headers do not persist in storage, and when the collection is released, whether with messages or not, the GroupHeader objects cease to exist.
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.
You can delete all the group headers and messages in the Messages collection by calling the collections Delete method. The ability to delete any message 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 Message object. That reference survives the call to Delete and has to be reassigned. The second Message object is deleted without creating another reference, and no other action is necessary.
' assume valid Folder object Set objMessage = objFolder.Messages.Item(1) objMessage.Delete ' still have a reference from Set statement ' ... other operations on objMessage possible but pointless ... Set objMessage = Nothing ' necessary to remove reference ' ... objFolder.Messages.Item(2).Delete ' no reference to remove