Unable to delete current form's mail from Sent folder

R

Rahul

Hi,

I am using Outlook 2003 and have designed and coded an Outlook custom form.

When a requestor submits the form, the copy in sent folders should be
deleted permanently. I am able to delete based on the Subject line except the
latest/current form which was submitted. So there is always one copy of the
form in Requestor's sent items. Please help me delete even the current form
from Sent items by modifying the below code since only this style of coding
works in my Outlook.

Function deleteItem()
Const olFolderSentMail = 5
Const olFolderDeletedItems = 3

strUniqueSubject = "ABCD Form"
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNamespace.GetDefaultFolder(olFolderSentMail)
Set colItems = objFolder.Items

For each objItem in colItems
If objItem.Subject = strUniqueSubject Then
msgbox "SentItems: "&objItem.Subject
objItem.delete
End if
Next

Set objFolder = objNamespace.GetDefaultFolder(olFolderDeletedItems)
Set colItems = objFolder.Items

For each objItem in colItems
If objItem.Subject = strUniqueSubject Then
msgbox "Delete Items"
objItem.delete
End if
Next

End Function

Thanks,

Rahul...
 
K

Ken Slovak - [MVP - Outlook]

This is Outlook form code? If so do not use CreateObject for your
Application object, use the intrinsic Application object provided to you. If
you are trying to delete the item that the form represents forget about it.
That can't be done from within the form code for that form.

Why not just set the DeleteAfterSubmit Boolean property before you send the
item? That way the sent item never even goes to Sent Items at all.
 
R

Rahul

Hi Ken

DeleteAfterSubmit Boolean did the job. Thanks a lot for letting me know
about that. Could you please tell me

1. If we have similar boolean for Forward. I need to delete form when I do a
forward. If there is no boolean then how should I go about deleting it from
sent items?
2. Which book to read to gain knowledge right from basic?

Thanks in advance.

Rahul...
 
K

Ken Slovak - [MVP - Outlook]

There's no flag that would prevent a user from forwarding, if that's what
you're asking. You'd have to handle the Forward event and either cancel it
or use the object passed in that event and set the DeleteAfterSubmit
property on the newly opened forwarded item.

Sue Mosher's book is a good beginner book but it doesn't cover COM addins or
VSTO or things like that. You can look at the list of books at
www.outlookcode.com for others. I'm partial to my book, but it's not really
a beginner's book it's more of an advanced level book as is Randy Byrne and
Ryan Gregg's book.
 

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