How to pemanently delete mail item using VBA?

G

Guest

I was using itemID but this did not work in all outlook clients
Any other way to do it

this is how i did it so far

Sub DeleteDelete(
Dim myOlApp, myNameSpace, Sel, objRecip, MyItem As Objec
Dim SavedEntryId,

Set myOlApp = CreateObject("Outlook.Application"
Set myNameSpace = myOlApp.GetNamespace("MAPI"

Set Sel = Application.ActiveExplorer.Selectio

For I = 1 To Sel.Coun
If Sel.Item(I).Class = olMail The
Set MyItem = Sel.Item(I
SavedEntryId = MyItem.EntryI
MyItem.Delete
Set MyItem = myNameSpace.GetItemFromID(SavedEntryId) ' <--- Run time error 8004010F, operation faile
MyItem.Delete
End I
Nex

End Sub
 
K

Ken Slovak - [MVP - Outlook]

If you delete an item in a PST file the EntryID won't change, which is due
to the transport provider for PST files. If you are using Exchange the
EntryID will change when an item is deleted. You cannot depend on an EntryID
remaining constant when an item is deleted.

You can handle the ItemAdd method on the Items collection of the Deleted
Items folder and delete the item as it's added to that collection. You can
add a UserProperty to the items before you delete them and check that
property when items are added to Deleted Items to make sure that you want to
permanently delete the item. A string property with the value "DeleteMe"
would do it.

Alternatively, you can use CDO 1.21 code (an optional installation for
Outlook 2000 and later) to permanently delete an item and bypassing Deleted
Items. CDO's Message.Delete method does that. See www.cdolive.com/cdo5.htm
for examples of CDO 1.21 code.




DavidB said:
I was using itemID but this did not work in all outlook clients.
Any other way to do it ?

this is how i did it so far:

Sub DeleteDelete()
Dim myOlApp, myNameSpace, Sel, objRecip, MyItem As Object
Dim SavedEntryId, I

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")

Set Sel = Application.ActiveExplorer.Selection

For I = 1 To Sel.Count
If Sel.Item(I).Class = olMail Then
Set MyItem = Sel.Item(I)
SavedEntryId = MyItem.EntryID
MyItem.Delete
Set MyItem = myNameSpace.GetItemFromID(SavedEntryId) '
<--- Run time error 8004010F, operation failed
 
G

Guest

Thanks
Once again this newsgroup is proven to be very helpfull
As in the past. when i get a good answer i proactively search for 3-4 pending questions and answer them from what i know. Others are enocuraged to do the same
Davi
 
S

Sue Mosher [MVP-Outlook]

That's the spirit!
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Thanks!
Once again this newsgroup is proven to be very helpfull.
As in the past. when i get a good answer i proactively search for 3-4
pending questions and answer them from what i know. Others are enocuraged to
do the same.
David
 

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