How are ya mudstuffin . . . . .
I knew I had done something in earlier years with OtuLook in this regard, but it was very hard to find (I finally realized just how big my library has become) . . .
Anyway , , , found it! So, in a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following [purple]function:[/purple]
Code:
[blue]Public Function DelSentOK(SubjectLine As String) As Boolean
Dim Fldr As MAPIFolder, SentItem As Object
Dim Msg As String, Style As Integer, Title As String, DL As String
On Error GoTo NoMail
DL = vbNewLine & vbNewLine
Set Fldr = CreateObject("Outlook.Application") _
.GetNameSpace("MAPI") _
.GetDefaultFolder(olFolderSentMail)
Set SentItem = Fldr.Items(SubjectLine) 'Break On Error Here![green][/green]
SentItem.Delete
DelSentOK = True
ExitErr:
Set SentItem = Nothing
Set Fldr = Nothing
Exit Function
NoMail:
If Err.Number = -2147221233 Then
Msg = "Sent Mail with subject line:" & DL & _
"'" & SubjectLine & "'" & DL & _
"Not Found!"
Style = vbInformation + vbOKOnly
Title = "Mail Not Found Error! . . ."
MsgBox Msg, Style, Title
Else
Msg = "Error Number " & Err.Number & DL & _
Err.Description
Style = vbCritical + vbOKOnly
Title = "System Error!"
MsgBox Msg, Style, Title
End If
Resume ExitErr
End Function[/blue]
The function returns [blue]True[/blue] if deletion was successful, [blue]False[/blue] otherwise (with a message).
To call the routine (example):
Code:
[blue]Variable = DelSentOK([purple][b]SubjectLine[/b][/purple])[/blue]
Things to take into account when making the call:
[ol][li]([purple]
[purple]SubjectLine[/purple][/purple] is the key for finding the sent e-mail. When you send the e-mail, this should be something unique and saved in a variable for the search.[/li]
[li]The function does not take into account multiple e-mails with the same [purple]
SubjectLine[/purple]. You may want to loop until an error is displayed![/li]
[li]Be aware: thre is a finite amount of time between the time the e-mail is sent and when it appeats in the [blue]Sent Folder.[/blue] Its up to you to work this out![/li][/ol]
See Ya! . . . . . .