troubleshooting Question

Outlook 2007- Auto Delete From Sent items Folder

Avatar of philmcfearless
philmcfearless asked on
Outlook
11 Comments1 Solution906 ViewsLast Modified:
Hi,
I Have code to delete messages from the sent items folder in Outlook 2007 when a message is sent to a certain email address.
It is soposed to check the folder once a email enters the folder.
It works sometimes but at other times will throw up a runtime error, and I cant seem to figure out why or what causes it.
I want it to be able to check sent folder at start up shutdown and when a message enters the sent items folder.

Dim myNS As NameSpace
Set myNS = GetNamespace("MAPI")
Dim msg As MailItem
For Each msg In myNS.GetDefaultFolder(olFolderSentMail).Items
   If msg.SenderEmailAddress = "ENTER EMAIL HERE" Then
    msg.Delete
End If
Next
End Sub
 
 
Private Sub olFolderSentMail_ItemAdd(ByVal Item As Object)
Dim myNS As NameSpace
Set myNS = GetNamespace("MAPI")
Dim msg As MailItem
For Each msg In myNS.GetDefaultFolder(olFolderSentMail).Items
   If msg.SenderEmailAddress = "ENTER EMAIL HERE" Then
    msg.Delete
End If
Next
End Sub
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros