![]() |
| If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|||||||
| Tags: advancedsearch, behavior |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Below I attempt a search that should succeed, which returns
results.count=0. Then I attempt a search that should fail; it returns results.count=0. Then I try to search folder "Deleted Items" which always gives "The Operation Failed" and Err numbers that vary wildly, though apparently always negative, e.g. -1386805681, -1352202673, -1317599665 (It does seem that it's been decreasing as the evening has progressed??!!). The 1st and 3rd answers bewilder me, and I hoped you could help. BTW, I am ignorant about "urn:schemas" and confess to have snagged this from other n/g posts; I assume that it lets me search the subject field. Worse yet, this is my first time using AdvancedSearch so forgive my ignorance. I am clear on using Application_AdvancedSearchComplete as sometimes shown in the n/g, but want to be comfortable with the above questions first. OL03. Both noted folders have items as I run this. Neither has a subfolder. Sub testSearch() Dim objSch As Search, strF As String strF=Chr(34) & "urn:schemas:httpmail:subject"" like 'News'" Set objSch = Application.AdvancedSearch _ (Scope:="Inbox", Filter:=strF, SearchSubFolders:=True) 'should work Debug.Print objSch.Results.Count strF=Chr(34) & "urn:schemas:httpmail:subject"" = 'ToStringTheImpossibleString'" Set objSch = Application.AdvancedSearch _ (Scope:="Inbox", Filter:=strF, SearchSubFolders:=True) 'should fail Debug.Print objSch.Results.Count Set objSch = Application.AdvancedSearch _ (Scope:="Deleted Items", Filter:=strF, SearchSubFolders:=True) End Sub |
| Ads |
|
#2
|
|||
|
|||
|
When you're using the Like operator, you need to include wildcards in the text you're searching for, e.g.:
strF=Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " Like '%News%'" I don't know why you're getting an error in searching Deleted Items. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook 2007 Programming: Jumpstart for Power Users and Administrators http://www.outlookcode.com/article.aspx?id=54 "Wild Bill" wrote in message ... Below I attempt a search that should succeed, which returns results.count=0. Then I attempt a search that should fail; it returns results.count=0. Then I try to search folder "Deleted Items" which always gives "The Operation Failed" and Err numbers that vary wildly, though apparently always negative, e.g. -1386805681, -1352202673, -1317599665 (It does seem that it's been decreasing as the evening has progressed??!!). The 1st and 3rd answers bewilder me, and I hoped you could help. BTW, I am ignorant about "urn:schemas" and confess to have snagged this from other n/g posts; I assume that it lets me search the subject field. Worse yet, this is my first time using AdvancedSearch so forgive my ignorance. I am clear on using Application_AdvancedSearchComplete as sometimes shown in the n/g, but want to be comfortable with the above questions first. OL03. Both noted folders have items as I run this. Neither has a subfolder. Sub testSearch() Dim objSch As Search, strF As String strF=Chr(34) & "urn:schemas:httpmail:subject"" like 'News'" Set objSch = Application.AdvancedSearch _ (Scope:="Inbox", Filter:=strF, SearchSubFolders:=True) 'should work Debug.Print objSch.Results.Count strF=Chr(34) & "urn:schemas:httpmail:subject"" = 'ToStringTheImpossibleString'" Set objSch = Application.AdvancedSearch _ (Scope:="Inbox", Filter:=strF, SearchSubFolders:=True) 'should fail Debug.Print objSch.Results.Count Set objSch = Application.AdvancedSearch _ (Scope:="Deleted Items", Filter:=strF, SearchSubFolders:=True) End Sub |
|
#3
|
|||
|
|||
|
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) -- 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 ... Below I attempt a search that should succeed, which returns results.count=0. Then I attempt a search that should fail; it returns results.count=0. Then I try to search folder "Deleted Items" which always gives "The Operation Failed" and Err numbers that vary wildly, though apparently always negative, e.g. -1386805681, -1352202673, -1317599665 (It does seem that it's been decreasing as the evening has progressed??!!). The 1st and 3rd answers bewilder me, and I hoped you could help. BTW, I am ignorant about "urn:schemas" and confess to have snagged this from other n/g posts; I assume that it lets me search the subject field. Worse yet, this is my first time using AdvancedSearch so forgive my ignorance. I am clear on using Application_AdvancedSearchComplete as sometimes shown in the n/g, but want to be comfortable with the above questions first. OL03. Both noted folders have items as I run this. Neither has a subfolder. Sub testSearch() Dim objSch As Search, strF As String strF=Chr(34) & "urn:schemas:httpmail:subject"" like 'News'" Set objSch = Application.AdvancedSearch _ (Scope:="Inbox", Filter:=strF, SearchSubFolders:=True) 'should work Debug.Print objSch.Results.Count strF=Chr(34) & "urn:schemas:httpmail:subject"" = 'ToStringTheImpossibleString'" Set objSch = Application.AdvancedSearch _ (Scope:="Inbox", Filter:=strF, SearchSubFolders:=True) 'should fail Debug.Print objSch.Results.Count Set objSch = Application.AdvancedSearch _ (Scope:="Deleted Items", Filter:=strF, SearchSubFolders:=True) End Sub |
|
#4
|
|||
|
|||
|
Thank you and Sue for each providing valuable specific insightful
instruction. I'll try each idea now. I had a latency problem so if I can't remove it in time, I reposted the question - please ignore it with my apologies. 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) |
|
#5
|
|||
|
|||
|
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) |
|
#6
|
|||
|
|||
|
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.) |
|
#7
|
|||
|
|||
|
Awesome - helluva thorough answer! Lots to work with. It brings to
mind, "I just hope you're not busy for about a month" - Tommy Chong, 1978 ![]() On Thu, 2 Aug 2007 08:57:02 -0400, "Ken Slovak - [MVP - Outlook]" wrote: 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. |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| AdvancedSearch and .Body | zofficedepot@hotmail.com | Outlook and VBA | 2 | July 26th 07 05:25 PM |
| AdvancedSearch Method | Irene | Outlook and VBA | 3 | December 8th 06 12:02 AM |
| Type of object for AdvancedSearch | Renjith | Outlook and VBA | 4 | May 17th 06 03:13 PM |
| Scope Parameter for AdvancedSearch | Renjith | Outlook - General Queries | 1 | May 12th 06 05:58 PM |
| AdvancedSearch | Serg Flic | Outlook and VBA | 1 | January 10th 06 04:17 PM |