Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating Outlook - The RESTRICT Method

Status
Not open for further replies.

comaboy

Programmer
Nov 6, 2001
261
GB
Wotcha!

Ok, I'm automating Outlook from VB and I want filter the Inbox (like the Find Items dialog) with some code something like this..

Code:
Function FindOutlookItem(strToFind As String)
    Dim ol As Object, olns, MyFolder, MyItems, myItem
   Set ol = CreateObject("Outlook.Application")
   Set olns = ol.GetNameSpace("MAPI")
   Set MyFolder = olns.GetDefaultFolder(olFolderInbox)
   Set MyItems = MyFolder.Items
   MyClause = "[Subject] Like ""*" & strToFind & "*""" ' This is want we want, but it'll throw a tantrum!
   Set MyACMEItems = MyItems.Restrict(MyClause)
   For Each myItem In MyACMEItems
      myItem.Display
   Next
End Function

...so that MyClause becomes an SQL LIKE operator..
FindOutlookItem "My Subject"
...runs as...
[Subject] Like '*My Subject*'

The only problem is that both the Restict and Find methods don't like the Like operator (ouch!)

Any idea how just get the items Filtered? There must be a way to do this! - and the M$ documentation doesn't help much - so no change there !

TIA,

Comaboy
 
Well, as far as the documentation I could find I hate to say it but I dont think that the filter in Outlook supports the like operator or any other contains type of operator.

The following is from MS documentation.

"
It is not possible to use these methods if you need to search for a string that’s contained within an Outlook field, commonly called a "Contains" operation. If you need to perform a Contains operation, you can iterate through all of the items in the folder and use the Visual Basic InStr function to see if your search string is contained within an Outlook field.
"

So you would need to cycle through each item and then run instr with the text you are looking for. And then flag those as matching for the results. bummer....

But then again somebody else may know a slicker work around.
 
TOTAL bummer !

This is typical M$ madness. We know it can done, it's a bloody button on the toolbar, so why no docs?

As for iterating through each item and instr-ing it from VB - talk about 'expensive'. I don't want to write a resource-killer!

Guess I'll end up having no option. Oh well, thanx for the input!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top