Results 1 to 2 of 2
2003-08-13, 01:38 #1
- Join Date
- Feb 2001
- Auckland, North Island, New Zealand
- Thanked 0 Times in 0 Posts
advancedsearchcomplete not firing? (Outlook 2002)
The sub MoveMail (below)seems to run (how can I be sure?) but never triggers the sub olapp_AdvancedSearchComplete.
Both these subs are in a standard module with:
Dim WithEvents olApp As Outlook.Application
in a class module (don't really understand if this is required - but didn't work when application_AdvancedSearchComplete was used)
What am I doing wrong?
Will the search look for every item with baby in the subject line or do I need to add wild cards?
Do I need to do anything to enable events?
Thanks in advance.
'performs searchs on specified folder to move mail to a sub folder based on subject contents.
Dim ObjSch As Search
Const StrSubject As String = "urn:schemas:mailheader:subject " 'look in subject field
Dim StrFolder As String
Dim StrFind As String 'what to look for
Dim strSearchTag As String 'set as conddest value
Dim CondDest(1 To 10, 1 To 2) '10 conditions into 1, 2 is for destination folder
Dim x As Integer
CondDest(1, 1) = "LIKE 'baby'" 'search for *baby*
CondDest(1, 2) = "GIS" 'folder
Set MyFolder = Application.GetNamespace("MAPI").PickFolder
For x = 1 To 1 'UBound (CondDest, 1) 'this will change when more searches required
If TypeName(CondDest(x, 1)) = "Empty" Then Exit Sub 'dno't search where array not filled
StrFind = CondDest(x, 1)
'Load parameter for search
StrFind = StrSubject & StrFind 'Filter
'StrFind = "urn:schemas:mailheader:subject" & " LIKE 'FW:%'"
StrFolder = "SCOPE ('shallow traversal of """ & MyFolder.FolderPath & """ ')" 'folder as picked
strSearchTag = CondDest(x, 2) 'needs to be folder so it can be used in results sub more easily
Set ObjSch = Application.AdvancedSearch(Scope:=StrFolder, Filter:=StrFind, Tag:=strSearchTag)
'all appears to work but never triggers event
Private Sub olapp_AdvancedSearchComplete(ByVal SearchObject As Search)
'triggered when a search is complete
Dim ObjRsts As Results
MsgBox "search " & SearchObject.Tag & " completed"
'Set ObjRsts = SearchObject.Results
'For Each item In ObjRsts
2003-08-13, 03:31 #2
- Join Date
- Feb 2001
- Silicon Valley, USA
- Thanked 94 Times in 90 Posts
Re: advancedsearchcomplete not firing? (Outlook 2002)
Take a look at my <post#=283107>post 283107</post#> for suggestions (by analogy) on where to put the event handling code. Hope this helps.