
Programmatically delete an item from the Sent Items Folder
I have tried to resolve this myself, but without success.
I also posted this message tem minutes ago, but maybe that
went wrong too ...
Thanks to earlier help from this site I have been able to
get my VB application to send e-mails via Outlook and keep
a copy of the sent e-mail in a Public folder.
Moving on from there, I would also like to be able to
programmatically remove the copy of the e-mail from the
Sent Items folder, leaving just the one in the Public
one. Is this possible or is there some kind of
restriction in place?
I have tried using the code below, but although it does
not fall over, it does not work either!!
Could someone please review this code and perhaps point me
in the right direction.
I thank you for any help that you can provide.
John J.
---
Note: This code is called directly after the VB
application sends the e-mail.
Sub DeleteSentItem()
Dim oSentItemsFolder As Outlook.MAPIFolder
Dim oDeleteFolder As Outlook.MAPIFolder
Dim objOutlook As Outlook.Application
Dim oMapi As Outlook.NameSpace
Dim oItems As Outlook.Items
Dim oItem As Outlook.MailItem
Set objOutlook = New Outlook.Application
Set oMapi = objOutlook.GetNamespace("MAPI")
Set oSentItemsFolder = oMapi.GetDefaultFolder
(olFolderSentMail)
Set oDeleteFolder = oMapi.GetDefaultFolder
(olFolderDeletedItems)
Set oItems = oSentItemsFolder.Items
Set oItem = oItems.Find("[Subject] = 'Test - Subject'")
oItem.Delete
Set objOutlook = Nothing
Set oMapi = Nothing
Set oSentItemsFolder = Nothing
Set oDeleteFolder = Nothing
Set oItems = Nothing
Set oItem = Nothing
End Sub