View Single Post
  #5  
Old August 2nd 07, 06:09 AM posted to microsoft.public.outlook.program_vba
Wild Bill
external usenet poster
 
Posts: 13
Default AdvancedSearch behavior

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.)

On Wed, 1 Aug 2007 09:48:09 -0400, "Ken Slovak - [MVP - Outlook]"
wrote:

That is the correct DASL property tag for Subject (DASL is a query language
used for Advanced Search, among other things).

For the second search I'd write the search term this way to avoid errors:
strF = Chr(34) & "urn:schemas:httpmail:subject"" =
'ToStringTheImpossibleString'"

I would expect no results at all for your debug.print statements, the
AdvancedSearch method call returns right away and you get your results
asynchronously in the AdvancedSearch.Complete event handler.

For your final search term use something like this, always putting single
quotes around any folder name that has a space in it:

Set objSch = Application.AdvancedSearch _
(Scope:="'Deleted Items'", Filter:=strF, SearchSubFolders:=True)


Ads
 

Free SMS - Credit Card - Bankruptcy - Credit Cards - Encyclopaedia