Empty deleted items folder through code

  • Thread starter Thread starter jake
  • Start date Start date
J

jake

Is there a way to empty the deleted items folder through
code, or can a mail item be deleted without sending it to
the deleted items folder in code?

Thanks.
 
Two methods to delete an item permanently:

1) Use the Delete method on the item, then find the same item in the Deleted Items folder, maybe using the Find method to match the subject, and delete it, too.

2) Use CDO's Delete method on the item, which will delete it permanently in one step. Sample code at http://www.outlookcode.com/codedetail.aspx?id=41

Note that CDO is not part of the default Outlook installation. You may need to rerun setup and add it.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
To delete an item without sending it to Deleted Items you would need
to use CDO 1.21's Message.Delete method or the equivalent in Extended
MAPI.

You can get the Deleted Items folder, its Items collection and iterate
that and delete each item in the collection. Use a count-down loop for
this otherwise you will only delete every other item:

For i = colItems.Count To 1 Step -1
Set objObject = colItems.Item(i)
objObject.Delete
Next i
 
Back
Top