A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

AdvancedSearchComplete Even Not Firing



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 7th 06, 07:21 PM posted to microsoft.public.outlook.program_vba
Dav Banks
external usenet poster
 
Posts: 6
Default AdvancedSearchComplete Even Not Firing

Hi,
I'm having a bit of a problem getting the AdvancedSearchComplete to fire.
I'm sure my search is working - I added two message boxes after the search,
one so I could introduce a delay to allow the search to complete and a
second to check the count of the result. The count comes up good.
However, when I just let the function end and wait for the event to fire,
I get nothing. I'm sure it's something simple but I can't see it! Any ideas?


--- Code ---
Public objSrch As Search

Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim i As Integer
Dim scope As String
Static cnt

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'Test Messages
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
Set objSrch = Nothing
End Sub

Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
Dim rslt As Outlook.Results
Set rslt = SearchObject.Results
MsgBox "Test1"
MsgBox SearchObject.Tag '& " Complete with " & rslt.Count & " results"
End Sub
--- Code ---

db


Ads
  #2  
Old June 8th 06, 07:29 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default AdvancedSearchComplete Even Not Firing

Am Wed, 7 Jun 2006 14:21:21 -0400 schrieb Dav Banks:

Set objSrch = Nothing


Please move that line into the SearchComplete event. (That sample you could
also do without the variable.)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


Hi,
I'm having a bit of a problem getting the AdvancedSearchComplete to

fire.
I'm sure my search is working - I added two message boxes after the

search,
one so I could introduce a delay to allow the search to complete and a
second to check the count of the result. The count comes up good.
However, when I just let the function end and wait for the event to

fire,
I get nothing. I'm sure it's something simple but I can't see it! Any

ideas?


--- Code ---
Public objSrch As Search

Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim i As Integer
Dim scope As String
Static cnt

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'Test Messages
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
Set objSrch = Nothing
End Sub

Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As

Search)
Dim rslt As Outlook.Results
Set rslt = SearchObject.Results
MsgBox "Test1"
MsgBox SearchObject.Tag '& " Complete with " & rslt.Count & " results"
End Sub
--- Code ---

db

  #3  
Old June 8th 06, 01:59 PM posted to microsoft.public.outlook.program_vba
Dav Banks
external usenet poster
 
Posts: 6
Default AdvancedSearchComplete Even Not Firing

Thanks for the feedback!

Moving the line did not help. Nor did removing it.

The event doesn't seemed to be called at all, i.e., the 'Test1' message is
never displayed. I was thinking it had something to do with how it was
declared or maybe not being attached to the application object somehow. I've
tried declaring it as Public and Private - I've seen it done both ways. But
neither worked.

db


"Michael Bauer" wrote in message
...
Am Wed, 7 Jun 2006 14:21:21 -0400 schrieb Dav Banks:

Set objSrch = Nothing


Please move that line into the SearchComplete event. (That sample you
could
also do without the variable.)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


Hi,
I'm having a bit of a problem getting the AdvancedSearchComplete to

fire.
I'm sure my search is working - I added two message boxes after the

search,
one so I could introduce a delay to allow the search to complete and a
second to check the count of the result. The count comes up good.
However, when I just let the function end and wait for the event to

fire,
I get nothing. I'm sure it's something simple but I can't see it! Any

ideas?


--- Code ---
Public objSrch As Search

Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim i As Integer
Dim scope As String
Static cnt

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'Test Messages
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
Set objSrch = Nothing
End Sub

Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As

Search)
Dim rslt As Outlook.Results
Set rslt = SearchObject.Results
MsgBox "Test1"
MsgBox SearchObject.Tag '& " Complete with " & rslt.Count & "
results"
End Sub
--- Code ---

db



  #4  
Old June 8th 06, 03:03 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default AdvancedSearchComplete Even Not Firing

Where is your search complete procedure running? Is it in the
ThisOutlookSession class or another class module or do you have it in a code
module where the callback wouldn't fire?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dav Banks" wrote in message
...
Hi,
I'm having a bit of a problem getting the AdvancedSearchComplete to
fire. I'm sure my search is working - I added two message boxes after the
search, one so I could introduce a delay to allow the search to complete
and a second to check the count of the result. The count comes up good.
However, when I just let the function end and wait for the event to
fire, I get nothing. I'm sure it's something simple but I can't see it!
Any ideas?


--- Code ---
Public objSrch As Search

Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim i As Integer
Dim scope As String
Static cnt

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'Test Messages
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
Set objSrch = Nothing
End Sub

Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As
Search)
Dim rslt As Outlook.Results
Set rslt = SearchObject.Results
MsgBox "Test1"
MsgBox SearchObject.Tag '& " Complete with " & rslt.Count & " results"
End Sub
--- Code ---

db



  #5  
Old June 8th 06, 03:23 PM posted to microsoft.public.outlook.program_vba
Dav Banks
external usenet poster
 
Posts: 6
Default AdvancedSearchComplete Even Not Firing

So...

I got the event to fire by moving the event code to the 'ThisOutlookSession'
module but the while...DoEvents loop seems to not respond now. I put a
message box in the event code to test firing and the while condition - both
were good - but the while loop seems never to end - the code after it is
never executed.

-- ThisOutlookSession --
Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As Search)
Set rslt = SearchObject.Results
'MsgBox SearchObject.Tag & " Complete with " & rslt.Count & " results"
'MsgBox rslt Is Nothing
blnSearchComp = True
'Set objSrch = Nothing
End Sub

-- Form Code --
Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim scope As String

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
blnSearchComp = False
Set rslt = Nothing
'While blnSearchComp = False
While rslt Is Nothing
DoEvents
Wend
MsgBox "Hello"
MsgBox rslt.Count
End Sub


db
"Dav Banks" wrote in message
...
Thanks for the feedback!

Moving the line did not help. Nor did removing it.

The event doesn't seemed to be called at all, i.e., the 'Test1' message is
never displayed. I was thinking it had something to do with how it was
declared or maybe not being attached to the application object somehow.
I've tried declaring it as Public and Private - I've seen it done both
ways. But neither worked.

db


"Michael Bauer" wrote in message
...
Am Wed, 7 Jun 2006 14:21:21 -0400 schrieb Dav Banks:

Set objSrch = Nothing


Please move that line into the SearchComplete event. (That sample you
could
also do without the variable.)

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


Hi,
I'm having a bit of a problem getting the AdvancedSearchComplete to

fire.
I'm sure my search is working - I added two message boxes after the

search,
one so I could introduce a delay to allow the search to complete and a
second to check the count of the result. The count comes up good.
However, when I just let the function end and wait for the event to

fire,
I get nothing. I'm sure it's something simple but I can't see it! Any

ideas?


--- Code ---
Public objSrch As Search

Public Sub Archive(fldSource As MAPIFolder, fldDestination As
MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim i As Integer
Dim scope As String
Static cnt

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'Test Messages
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
Set objSrch = Nothing
End Sub

Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As

Search)
Dim rslt As Outlook.Results
Set rslt = SearchObject.Results
MsgBox "Test1"
MsgBox SearchObject.Tag '& " Complete with " & rslt.Count & "
results"
End Sub
--- Code ---

db





  #6  
Old June 8th 06, 03:47 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default AdvancedSearchComplete Even Not Firing

I don't see why you need a Do Loop. Just have the complete event do whatever
you want. Or set up a global Boolean in a code module and set it False on
starting the search and True in the complete event.

Where is that result object declared? Is it declared with global scope?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dav Banks" wrote in message
...
So...

I got the event to fire by moving the event code to the
'ThisOutlookSession' module but the while...DoEvents loop seems to not
respond now. I put a message box in the event code to test firing and the
while condition - both were good - but the while loop seems never to end -
the code after it is never executed.

-- ThisOutlookSession --
Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As
Search)
Set rslt = SearchObject.Results
'MsgBox SearchObject.Tag & " Complete with " & rslt.Count & " results"
'MsgBox rslt Is Nothing
blnSearchComp = True
'Set objSrch = Nothing
End Sub

-- Form Code --
Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim scope As String

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
blnSearchComp = False
Set rslt = Nothing
'While blnSearchComp = False
While rslt Is Nothing
DoEvents
Wend
MsgBox "Hello"
MsgBox rslt.Count
End Sub


db


  #7  
Old June 8th 06, 04:04 PM posted to microsoft.public.outlook.program_vba
Dav Banks
external usenet poster
 
Posts: 6
Default AdvancedSearchComplete Even Not Firing

I was using the examples from this group that other people seemed to have
success with. I initially used a global Boolean (blnSearchComp in the code)
but it had the same results - the while loop never saw the change in value
after the complete event fired.

I've had the result object declared public at the global level of both the
code module and the ThisOutlookSession module with the same results.

I wanted to go this way because I eventually want the Archive routine to be
recursive but I didn't want it to bog down the system by calling many
searches before the previous one finished. This way I could do one at a
time.

Is there any reason why the while loop isn't seeing the variable value
change?

db


"Ken Slovak - [MVP - Outlook]" wrote in message
...
I don't see why you need a Do Loop. Just have the complete event do
whatever you want. Or set up a global Boolean in a code module and set it
False on starting the search and True in the complete event.

Where is that result object declared? Is it declared with global scope?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dav Banks" wrote in message
...
So...

I got the event to fire by moving the event code to the
'ThisOutlookSession' module but the while...DoEvents loop seems to not
respond now. I put a message box in the event code to test firing and the
while condition - both were good - but the while loop seems never to
end - the code after it is never executed.

-- ThisOutlookSession --
Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As
Search)
Set rslt = SearchObject.Results
'MsgBox SearchObject.Tag & " Complete with " & rslt.Count & " results"
'MsgBox rslt Is Nothing
blnSearchComp = True
'Set objSrch = Nothing
End Sub

-- Form Code --
Public Sub Archive(fldSource As MAPIFolder, fldDestination As MAPIFolder,
date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim scope As String

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
blnSearchComp = False
Set rslt = Nothing
'While blnSearchComp = False
While rslt Is Nothing
DoEvents
Wend
MsgBox "Hello"
MsgBox rslt.Count
End Sub


db




  #8  
Old June 8th 06, 06:54 PM posted to microsoft.public.outlook.program_vba
Dav Banks
external usenet poster
 
Posts: 6
Default AdvancedSearchComplete Even Not Firing

What worked...

Declaring the results object and the Boolean as global in the form code.
Referring to the objects with the form name from the ThisOutlookSession...
Archive.blnSearchComp = True
Set Archive.rslt = SerchObject.Results

db

"Dav Banks" wrote in message
...
I was using the examples from this group that other people seemed to have
success with. I initially used a global Boolean (blnSearchComp in the code)
but it had the same results - the while loop never saw the change in value
after the complete event fired.

I've had the result object declared public at the global level of both the
code module and the ThisOutlookSession module with the same results.

I wanted to go this way because I eventually want the Archive routine to
be recursive but I didn't want it to bog down the system by calling many
searches before the previous one finished. This way I could do one at a
time.

Is there any reason why the while loop isn't seeing the variable value
change?

db


"Ken Slovak - [MVP - Outlook]" wrote in message
...
I don't see why you need a Do Loop. Just have the complete event do
whatever you want. Or set up a global Boolean in a code module and set it
False on starting the search and True in the complete event.

Where is that result object declared? Is it declared with global scope?

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dav Banks" wrote in message
...
So...

I got the event to fire by moving the event code to the
'ThisOutlookSession' module but the while...DoEvents loop seems to not
respond now. I put a message box in the event code to test firing and
the while condition - both were good - but the while loop seems never to
end - the code after it is never executed.

-- ThisOutlookSession --
Public Sub Application_AdvancedSearchComplete(ByVal SearchObject As
Search)
Set rslt = SearchObject.Results
'MsgBox SearchObject.Tag & " Complete with " & rslt.Count & "
results"
'MsgBox rslt Is Nothing
blnSearchComp = True
'Set objSrch = Nothing
End Sub

-- Form Code --
Public Sub Archive(fldSource As MAPIFolder, fldDestination As
MAPIFolder, date1 As Date, Optional recursive As Boolean = False)
Dim fldNewDest As MAPIFolder
Dim fldNewSource As MAPIFolder
Dim fldMail As MailItem
Dim scope As String

Const srch As String = """urn:schemas:httpmail:datereceived"" =
'1/1/2005'"
scope = "SCOPE ('shallow traversal of """ & fldSource.FolderPath &
"""')"
Set objSrch = Application.AdvancedSearch(scope, srch, False, "Test")
'MsgBox "Filter = " & objSrch.Filter & Chr(13) _
& "Folder = " & objSrch.scope
'MsgBox objSrch.Results.Count
blnSearchComp = False
Set rslt = Nothing
'While blnSearchComp = False
While rslt Is Nothing
DoEvents
Wend
MsgBox "Hello"
MsgBox rslt.Count
End Sub


db






  #9  
Old June 8th 06, 09:18 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default AdvancedSearchComplete Even Not Firing

Ah, then they weren't true globals. Those would have been declared as Public
in a code module, not a form or class. In a form or class you always would
need to qualify your reference with the class or form object.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Dav Banks" wrote in message
...
What worked...

Declaring the results object and the Boolean as global in the form code.
Referring to the objects with the form name from the ThisOutlookSession...
Archive.blnSearchComp = True
Set Archive.rslt = SerchObject.Results

db


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
AdvancedSearchComplete Renjith Outlook and VBA 0 May 24th 06 07:44 AM
Inspector Close events not firing.. Sanjay Add-ins for Outlook 1 May 22nd 06 06:18 PM
MapiFolder Items ItemChange is not firing AtulSureka Outlook - Using Forms 1 February 6th 06 04:32 PM
Mapi Folder Items ItemChange event is not firing AtulSureka Outlook and VBA 3 February 5th 06 06:25 PM
Outlook Addin CommandBarButton Click Event Not Firing Stu Add-ins for Outlook 0 January 17th 06 02:10 AM


All times are GMT +1. The time now is 03:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.