Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    Auckland, North Island, New Zealand
    Posts
    83
    Thanks
    0
    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.



    Sub MoveMail()

    'performs searchs on specified folder to move mail to a sub folder based on subject contents.
    Dim ObjSch As Search
    Dim MyFolder
    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

    ''load array
    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
    'Do Search
    Set ObjSch = Application.AdvancedSearch(Scope:=StrFolder, Filter:=StrFind, Tag:=strSearchTag)
    'all appears to work but never triggers event
    Next x
    End Sub


    Private Sub olapp_AdvancedSearchComplete(ByVal SearchObject As Search)

    'triggered when a search is complete
    Dim ObjRsts As Results
    Dim item

    MsgBox "search " & SearchObject.Tag & " completed"

    'Set ObjRsts = SearchObject.Results
    'For Each item In ObjRsts
    'item.Move SearchObject.Tag
    'Next
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •