View Single Post
  #6  
Old August 2nd 07, 02:57 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 3,948
Default AdvancedSearch behavior

To search in multiple folders in one search you can separate the list of
folders with commas, I find it works best in those cases if I surround each
folder name with single quotes whether or not they have spaces in the names.
All the searched folders must be in the same mail store (PST or mailbox),
you can't search across stores.

To be able to identify various searches when they complete and fire the
AdvancedSearchComplete event you add unique Tag properties to each search
you start, then check the Tag of the completed search when it's passed to
you in that event handler.

You can aggregate the searches in any way you want: a listbox, grid control,
disconnected recordset, a collection, the list is limited by your
imagination. I often use a grid control when I want to aggregate results
from multiple folders into one visual interface.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Wild Bill" wrote in message
...
Yes, ' around folder name 'Deleted Items' was the salvation. And the
asynchronous explanation for the count makes PERFECT sense. And
doohhhhh of course without % the Like was useless. Thank you, thank
you, thank you.

A couple of new questions (for anyone): I understand you can run a
boatload of these async. processes, so I ran all three and *then* went
Test... a la

Public blnSearchComp As Boolean
Sub testSearchAsPostedInNG()
Dim objSch As Search, strF As String

strF = Chr(34) & "urn:schemas:httpmail:subject"" like '%News%'"
'should succeed
Set objSch = Application.AdvancedSearch(Scope:="'Inbox'",
Filter:=strF, SearchSubFolders:=True)
'TestAdvancedSearchComplete 'commented to try doing 3 at once
Debug.Print objSch.Results.Count

strF = Chr(34) & "urn:schemas:httpmail:subject"" =
'ToStringTheImpossibleString'" 'should fail
Set objSch = Application.AdvancedSearch(Scope:="'Inbox'",
Filter:=strF, SearchSubFolders:=True)
'TestAdvancedSearchComplete 'commented to try doing 3 at once
Debug.Print objSch.Results.Count

Set objSch = Application.AdvancedSearch(Scope:="'Deleted Items'",
Filter:=strF, SearchSubFolders:=True)
TestAdvancedSearchComplete
Debug.Print objSch.Results.Count
End Sub
Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As
Search)
MsgBox "The AdvancedSearchComplete Event fired"
blnSearchComp = True
End Sub
Sub TestAdvancedSearchComplete()
Dim sch As Outlook.Search
Dim rsts As Outlook.Results
Dim i As Integer
blnSearchComp = False
Const strF As String = "urn:schemas:httpmail:subject LIKE
'%mykeyword%'"
Const strS As String = "Inbox"
Set sch = Application.AdvancedSearch(strS, strF)
While blnSearchComp = False
DoEvents
Wend
Set rsts = sch.Results
For i = 1 To rsts.Count
MsgBox rsts.Item(i).SenderName
Next
End Sub

I'd like to tell you how that went but it ran for an hour at about full
CPU and I had to kill OL. I guess I want to ask, how would you
distinguish the 3 result sets in this case? And could I concatenate
them?

Now, if I uncommented the 2 lines and ran all 3 Test... calls then
clearly I could distinguish the 3 result sets, so perhaps I might build
a listbox from the result items. But I'd far prefer to have an OL folder
interface. But since Sue says you can't append to a Search result
folder, do I have any options for a multi-folder result set? (Maybe I
should also ask if scope can be built from several folders, when the
search filter is to be identical for each.)


Ads
 

Mobile Themes Download - Pinoy Sites - Remortgaging - Xbox Mod Chip - Personal Injury Lawyer Los Angeles