Trying to emulate a "Find" in code

  • Thread starter Thread starter Wayne Harpster
  • Start date Start date
W

Wayne Harpster

I am trying to filter the email items that are displayed based on the
contents of the subject line and including items from (2) different
folders (specifically, the Inbox and the Sent Items folders). I've tried
a number of methods to accomplish this but it's not coming together for
me.

I am using Outlook 2003 and Windows 2000.

Any help?
 
I hadn't, but I have now. I tried this:

Private Sub Command1_Click()
Dim myOlApp As Outlook.Application
Dim sch As Outlook.Search
Dim rsts As Outlook.Results
Set sch = myOlApp.AdvancedSearch _
("'Inbox', 'Sent Items'", "urn:schemas:mailheader:subject
= '38867B10'")
Set rsts = sch.Results
end sub

This runs, but rsts ends up with (1) item and that (1) item is empty. My
Inbox has (6) items whose subject contains 38867B10.

Got any hints as to what I'm doing wrong?
 
I hadn't, but I have now. I tried this:

Private Sub Command1_Click()
Dim myOlApp As Outlook.Application
Dim sch As Outlook.Search
Dim rsts As Outlook.Results
Set sch = myOlApp.AdvancedSearch _
("'Inbox', 'Sent Items'", "urn:schemas:mailheader:subject
= '38867B10'")
Set rsts = sch.Results
end sub

This runs, but rsts ends up with (1) item and that (1) item is empty. My
Inbox has (6) items whose subject contains 38867B10.

Got any hints as to what I'm doing wrong?
 
The search runs asynchronously, you need to wait for the search to finish.
Use the Application.AdvancedSearchComplete event for that. Use the Tag
parameter/property to distinguish between different search objects.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top