AdvancedSearchComplete not called from Outlook rule


Jun 9, 2009
Reaction score
Hi all,

I’ve been writing a couple of scripts intended for use with Outlook rules which use AdvancedSearch to find related messages, but I’ve run into a strange problem – when these scripts are called by an Outlook rule, and no other time, AdvancedSearchComplete is not being called. Here’s an example:

Sub testAppSearchCompleteScript(NewMail As MailItem)
    	Debug.Print "Before macro call"
    	Debug.Print "After Macro call"
    End Sub
    Sub testAppSearchComplete()
    	Dim s As
    	Dim filter As String
    	filter = "urn:schemas:httpmail:subject = 'Test'"
    	Debug.Print "Before search"
    	Set s = Application.AdvancedSearch("Inbox", filter, True, "Test")
    	Debug.Print "After search"
    End Sub
    Private Sub Application_AdvancedSearchComplete(ByVal SearchObject As search)
    	Dim results As Outlook.results
    	Dim task As MailItem
    	Set results = SearchObject.results
    	Debug.Print "Search with tag '" & SearchObject.Tag & "' has completed."
    	If SearchObject.Tag = "Test" Then
    		Debug.Print ("Test Result count: " & results.Count)
    	End If
    End Sub

The script testAppSearchCompleteScript is called by an outlook rule. It then calls the testAppSearchComplete macro, which does an actual search with hardcoded test information. When I run the macro through the VB editor or through Outlook in Tools->Macro->Macros, it works perfectly – here’s the output:

Before search

After search

Search with tag 'Test' has completed.

Test Result count: 0

But when I run the Outlook rule, everything works but the AdvancedSearchComplete event never fires – here’s the output:

Before macro call

Before search

After search

After Macro call

I’ve looked all over the Internet but I can’t find anything about this. I read somewhere that there is a maximum of 100 searches at a time – could that be related? I’m running Office 2007 on WinXP Pro SP2. My macro is signed and trusted by Outlook. Has anyone seen this before?

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question