F
federico
Hello, I am trying to setup a Visual Basic "Console" application for
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete Event. The problem I
have is that the application finishes and exits before the AdvanceSearch, so
the Event Handler in never called. If I delay the end of the application,
for example, by having message box right after the call to AdvancedSearch,
the search completes, its handler is executed, and it correctly reports the
number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop
Module Module1
Sub Main()
Dim App As New Outlook.Application
AddHandler App.AdvancedSearchComplete, AddressOf
App_AdvancedSearchComplete
App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE
'%test'", False, "TestSearch")
MsgBox("pause")
End Sub
Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search)
MsgBox("Search done. Found " & oSearch.Results.Count & " emails")
End Sub
End Module
However, if I remove the msgbox call under Main, App_AdvancedSearchComplete
is not executed.
I tried the same code on a "Windows" application, and it works fine, but I
would prefer to use a console application.
I would appreciate any suggestions anyone would have.
Thanks in advance.
federico
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete Event. The problem I
have is that the application finishes and exits before the AdvanceSearch, so
the Event Handler in never called. If I delay the end of the application,
for example, by having message box right after the call to AdvancedSearch,
the search completes, its handler is executed, and it correctly reports the
number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop
Module Module1
Sub Main()
Dim App As New Outlook.Application
AddHandler App.AdvancedSearchComplete, AddressOf
App_AdvancedSearchComplete
App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE
'%test'", False, "TestSearch")
MsgBox("pause")
End Sub
Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search)
MsgBox("Search done. Found " & oSearch.Results.Count & " emails")
End Sub
End Module
However, if I remove the msgbox call under Main, App_AdvancedSearchComplete
is not executed.
I tried the same code on a "Windows" application, and it works fine, but I
would prefer to use a console application.
I would appreciate any suggestions anyone would have.
Thanks in advance.
federico