Using all emails from a category

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Team,

When one of my users clicks a button on my Outlook toolbar, I want to
perform an action with all the emails that are in the same category as the
currently selected email.

I am currently doing this using this psuedocode:

for each Item in objCurrentFolder.FolderItems
If item has the correct category
Add the item to a collection
End if
next Item

This strikes me as fairly clumsy though. If there are any large number of
items in the folder, it takes a long time just to check the type of each item
and see if they belong in my collection or not.

Can anyone think of any better way of doing this?

Much appreciated,
Rob
 
You could use a restriction on the Items collection using Categories to
narrow things down. It will return all items that have that category (alone
or among other categories).
 
Hi Ken,

Thanks for that very rapid response.

Is a restriction the same as an advanced search?

I'm not familiar with the term.

Thanks,
Rob
 
A restriction is applied to the Items collection of a MAPIFolder.
Items.Restrict(search terms). The Object Browser has information on the
syntax and some examples. It would be something like this, where the result
is a restricted Items collection you can then iterate:

Set colFilteredItems = oFolder.Items.Restrict("[Categories] = " & Chr(34) &
"Foobar" & Chr(34))
 
Ken,

I'm very grateful for your fast and informative responses. I've got this
working great now, about twenty times the speed it was working using my old
method!

Ta,

Rob
 
Back
Top