Empty deleted items folder through code

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.
 
S

Sue Mosher [MVP]

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
 
K

Ken Slovak - [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top