Deleting inbound mail with rule and VBA

T

Tony Gravagno

I want to Outlook 2002 to delete inbound mail with a specific subject.
(Not just "with ... in the subject".) If I run a macro on all mail, I
don't know if I'm going to .Delete the MailItem or not. If I do
delete it, then I want to "Stop Processing" the rest of the rules.
But I can't put the Stop into the Rule ahead of time or it won't
process any of my other rules for items I don't delete. If I don't
"Stop Processing", another rule may eventually trip on it with:
"Cannot remove messages from the specified folder"

Rather than using .Delete from the VBA I tried to set the Category to
"DeleteMe", then the following rule just checks for that category, and
if it's found it should delete the mail and Stop processing.
Unfortunately setting .Categories and then using .Save doesn't seem to
really save the new status of the mail item immediately, and the rule
that checks the category doesn't get a match.

Rather than setting the Category I also tried setting the subject to a
unique string with the same results.

So, is there a way to .Delete in VBA and then Stop Processing rules?
Or, how do we post changes to the item so that another rule can see
those changes?

I actually do have a solution using code from Sue Mosher's site, by
tracking ItemAdd events on the Inbox I can Move items to
olFolderDeletedItems before the rules get to them. A less oblique
approach to the problem would be nice. :) Thanks Sue!

<vent>
BTW, as I was messing with this stuff, Outlook deleted my OTM and
everything I had in there. That prompted me to investigate and find
out this is a common issue. I REALLY wish if Microsoft didn't
actually fix issues that they would at least create patches that
warned us when we are close to triggering known bugs, like "Warning,
an undiagnosed bug may delete all of your code. Please export your
module as a VBA file before exiting."
</vent>

TIA
Tony Gravagno
Nebula R&D
(e-mail address removed)
 

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