AdvancedSearchComplete Search param not immediately ready for use

Status
Not open for further replies.
S

sb

Hello,

I am developing an Outlook add-in using VSTO in VS2008, using .Net 2.0 and

Outlook 2003. I have a bit of functionality that executes an advancedsearch

and catches the AdvancedSearchComplete event. However, when the results come

back, the Search parameter passed to the event handler does not appear to be

ready for use.

The search:

sFilter = "\"urn:schemas:httpmail:subject\" LIKE '%subject

string%' AND ";

sFilter += "\"urn:schemas:httpmail:textdescription\" LIKE '%text

description%'";

//Execute the search

try

{

Outlook.Application a = m_addIn.Application;

sScope = "'\\\\valid folder\\'";

a.AdvancedSearch(sScope, sFilter, true, "Tag");

}

The event handler:

private void m_outlook_AdvancedSearchComplete(Outlook.Search

searchObj)

{

//MessageBox.Show(searchObj.Results.Count.ToString());

for (int i = 1; i <= searchObj.Results.Count; i++)

{

//do stuff

}

Everything seems to be working fine, the search is successful and the

AdvancedSearchComplete event fires when it is done. However, when

AdvancedSearchComplete is fired as expected, searchObj.Results.Count is

ALWAYS zero. But... If that MessageBox.Show line is uncommented, it always

displays '0', but then the subsequent calls to searchObj in the for... and

beyond correctly reflect the search Results. I have tried a Thread.Sleep()

call in there to no avail.

Thoughts? I thought the results were guaranteed to be ready when this event

fires. Is there some setting I am missing somewhere?

thanks
 
K

Ken Slovak - [MVP - Outlook]

I can't repro that here using VS 2008, C# and Outlook 2003. I used this

search as a test:

Outlook.Search search = _outlook.AdvancedSearch("Inbox",

"urn:schemas:mailheader:subject = 'Checking in'", true, "Foo");

When the event fired the MessageBox showed 1 result in my Inbox, as

expected.

If you want to loop the Results collection you will need to use

GetFirst()/GetLast() or get an IEnumerator object to iterate the collection

that way.

"sb" <sb> wrote in message

news:AD2A8C67-09BE-41FA-9014-EDABFE24CB4D@microsoft.com...
> Hello,

> I am developing an Outlook add-in using VSTO in VS2008, using .Net 2.0 and
> Outlook 2003. I have a bit of functionality that executes an
> advancedsearch
> and catches the AdvancedSearchComplete event. However, when the results
> come
> back, the Search parameter passed to the event handler does not appear to
> be
> ready for use.

> The search:

> sFilter = "\"urn:schemas:httpmail:subject\" LIKE '%subject
> string%' AND ";
> sFilter += "\"urn:schemas:httpmail:textdescription\" LIKE
> '%text
> description%'";

> //Execute the search
> try
> {
> Outlook.Application a = m_addIn.Application;

> sScope = "'\\\\valid folder\\'";
> a.AdvancedSearch(sScope, sFilter, true, "Tag");
> }

> The event handler:

> private void m_outlook_AdvancedSearchComplete(Outlook.Search
> searchObj)
> {
> //MessageBox.Show(searchObj.Results.Count.ToString());

> for (int i = 1; i <= searchObj.Results.Count; i++)
> {
> //do stuff
> }

> Everything seems to be working fine, the search is successful and the
> AdvancedSearchComplete event fires when it is done. However, when
> AdvancedSearchComplete is fired as expected, searchObj.Results.Count is
> ALWAYS zero. But... If that MessageBox.Show line is uncommented, it
> always
> displays '0', but then the subsequent calls to searchObj in the for... and
> beyond correctly reflect the search Results. I have tried a
> Thread.Sleep()
> call in there to no avail.

> Thoughts? I thought the results were guaranteed to be ready when this
> event
> fires. Is there some setting I am missing somewhere?

> thanks
 
S

sb

Re: AdvancedSearchComplete Search param not immediately ready for

Thank you for your response, Ken.

It seems strange it only happens for me. Are you using .Net 2.0 (as opposed

to the VS2008 default of 3.5)? Also, I am running on Win 7 RC, and the email

accounts in my test config of Outlook are just a couple of hotmail addresses

using Outlook Connector. Not sure why any of these would make any difference.

In any event, I finally just solved this problem with an

Application.DoEvents() call in the event handler. Weird.

Forgive me, I am no Outlook extensibility master. While

GetFirst()/GetNext() may be better in some way, why would a for() loop not

work to iterate the results?

thanks
wrote:


> I can't repro that here using VS 2008, C# and Outlook 2003. I used this
> search as a test:

> Outlook.Search search = _outlook.AdvancedSearch("Inbox",
> "urn:schemas:mailheader:subject = 'Checking in'", true, "Foo");

> When the event fired the MessageBox showed 1 result in my Inbox, as
> expected.

> If you want to loop the Results collection you will need to use
> GetFirst()/GetLast() or get an IEnumerator object to iterate the collection
> that way.

> >

>

> "sb" <sb> wrote in message
> news:AD2A8C67-09BE-41FA-9014-EDABFE24CB4D@microsoft.com...
> > Hello,
> > I am developing an Outlook add-in using VSTO in VS2008, using .Net 2.0 and
> > Outlook 2003. I have a bit of functionality that executes an
> > advancedsearch
> > and catches the AdvancedSearchComplete event. However, when the results
> > come
> > back, the Search parameter passed to the event handler does not appear to
> > be
> > ready for use.
> > The search:
> > sFilter = "\"urn:schemas:httpmail:subject\" LIKE '%subject
> > string%' AND ";
> > sFilter += "\"urn:schemas:httpmail:textdescription\" LIKE
> > '%text
> > description%'";
> > //Execute the search
> > try
> > {
> > Outlook.Application a = m_addIn.Application;
> > sScope = "'\\\\valid folder\\'";
> > a.AdvancedSearch(sScope, sFilter, true, "Tag");
> > }
> > The event handler:
> > private void m_outlook_AdvancedSearchComplete(Outlook.Search
> > searchObj)
> > {
> > //MessageBox.Show(searchObj.Results.Count.ToString());
> > for (int i = 1; i <= searchObj.Results.Count; i++)
> > {
> > //do stuff
> > }
> > Everything seems to be working fine, the search is successful and the
> > AdvancedSearchComplete event fires when it is done. However, when
> > AdvancedSearchComplete is fired as expected, searchObj.Results.Count is
> > ALWAYS zero. But... If that MessageBox.Show line is uncommented, it
> > always
> > displays '0', but then the subsequent calls to searchObj in the for... and
> > beyond correctly reflect the search Results. I have tried a
> > Thread.Sleep()
> > call in there to no avail.
> > Thoughts? I thought the results were guaranteed to be ready when this
> > event
> > fires. Is there some setting I am missing somewhere?
> > thanks


>
 
K

Ken Slovak - [MVP - Outlook]

Re: AdvancedSearchComplete Search param not immediately ready for

I did the test in an addin I'm working on which happens to use Framework 2.0

and not 3.5. The code was tested on WinXP SP3 and Outlook 2003 SP3.

I'd guess that the connector and hotmail wouldn't make a difference, the

search is being done on a specific folder or folders. I don't use the

connector, are the folders you were searching local in a PST file? If so

then there shouldn't be a difference. I happened to test using a cached

Exchange mailbox.

I wonder if using Application.AdvancedSearch() as a function, as I did might

make a difference. You might try that and see.

I suggested using the Get* functions rather than something like

searchObject just because you don't have to deal with Outlook collections

starting with Item[1] and not Item[0]. One less thing to remember. Not a big

deal, I often use a for loop like yours.

"sb" <sb> wrote in message

news:170CA22D-495B-4399-ADE6-24A696A0E7E5@microsoft.com...
> Thank you for your response, Ken.

> It seems strange it only happens for me. Are you using .Net 2.0 (as
> opposed
> to the VS2008 default of 3.5)? Also, I am running on Win 7 RC, and the
> email
> accounts in my test config of Outlook are just a couple of hotmail
> addresses
> using Outlook Connector. Not sure why any of these would make any
> difference.

> In any event, I finally just solved this problem with an
> Application.DoEvents() call in the event handler. Weird.

> Forgive me, I am no Outlook extensibility master. While
> GetFirst()/GetNext() may be better in some way, why would a for() loop not
> work to iterate the results?

> thanks
 
S

sb

Re: AdvancedSearchComplete Search param not immediately ready for
wrote:



> I suggested using the Get* functions rather than something like
> searchObject just because you don't have to deal with Outlook collections
> starting with Item[1] and not Item[0]. One less thing to remember. Not a big
> deal, I often use a for loop like yours.
>


Ah yes - I already encountered and passed that annoyance. <g
Thanks again for your help.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Outlook search bar in Office 2021 Professional Using Outlook 1
T Outlook 365 Search Box reverting to old location Using Outlook 3
P Outlook 2013 search no longer works Using Outlook 2
C How to search for items in Outbox with multiple accounts? Using Outlook 14
J search doesn't find anything Using Outlook 1
kkqq1122 How would I add Search for attachment name Outlook VBA and Custom Forms 3
A Any way to force sort by/group by on search results with VBA? Outlook VBA and Custom Forms 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
C Search not accurate, but not indexing Using Outlook 9
J How do you disable address search box when typing @ in body of email? Using Outlook 0
H Outlook 2019 intermittent search results Using Outlook 0
D Create advanced search (email) via VBA with LONG QUERY (>1024 char) Outlook VBA and Custom Forms 2
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
mll persistently customise columns in outlook advanced search Using Outlook 3
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
S VBA search string with special characters Outlook VBA and Custom Forms 1
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
P Posts in Folder No Longer Group by Conversation Column After Search Using Outlook 0
O Advanced search - can I use booleans Using Outlook 3
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
M Reverting The Outlook Search Box Location (or other undesired additions) Using Outlook 1
M Something went wrong and your search couldn't be completed Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
P outlook 2008 search box criteria couldn't be saved Using Outlook 2
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
L New Location for the Search Bar Using Outlook 6
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
J Outlook 2016 After a search in all mailboxes, where is each message that was found? Using Outlook 6
King Mustard Sort search groups by amount of items? Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
T Search for incoming e-mails for a specified time range Using Outlook 1
S outlook 2007 calendar search Using Outlook 6
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
J Message search and edit, another way? Outlook VBA and Custom Forms 4
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
R Outlook for Mac - Advanced Search and Tracking Sent Emails Using Outlook 0
R Search/Jump to a folder by typing its name Outlook VBA and Custom Forms 1
M Sent mail not showing in Sent Items folder; but they can be found with Search Using Outlook 3
A Outlook 2019 having issues with 'people search' and not making suggestions in email To: etc Using Outlook 12
W Search Incomplete Outlook 2016 Using Outlook 5
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
R outlook address book search broken Using Outlook 2
K Outlook.com is not showing, or finding via search, all my Contacts (People) Using Outlook 0
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
R What's supposed to appear when just clicking into the search field? Using Outlook 7
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3

Similar threads

Top