none
find emails not working RRS feed

  • Question

  • why does this routine doesn't alsways find the mails , although they are there ?

    Private Sub Knop0_Click()
     Dim myNameSpace As outlook.NameSpace
     Dim myInbox As outlook.Folder
     Dim myDestFolder As outlook.Folder
     Dim myItems As outlook.Items
     Dim myItem As Object
     
     'mails met ingegeven naam verhuizen van inbox naar aaa'
     
     
     Set myNameSpace = outlook.Application.GetNamespace("MAPI")
     Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
     
     Set myItems = myInbox.Items
     
     Set myDestFolder = myInbox.Folders("aaa")
     
     
     Set myItem = myItems.Find("[SenderName] = '" & naam & "'")
     
       MsgBox TypeName(myItem)
     While TypeName(myItem) <> "Nothing"
     myItem.Move myDestFolder
     Set myItem = myItems.FindNext
     Wend
    End Sub

    Thursday, May 12, 2016 5:51 AM

Answers

  • Hi tekoko,

    Based on your code, it seems you want to find mailItem by SenderName. How did you set value for naam? The value for naam must be equal to the SenderName of the mailItem you want, and the MailItem must be in Index folder. You could try the code below to get real SenderName.

    Debug.Print myItems.GetFirst().SenderName
    

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by tekoko10 Friday, May 13, 2016 6:08 AM
    Friday, May 13, 2016 3:30 AM
  • Are you sure you have the correct name? Keep in mind the sender name can include the email address as well - check using OutlookSpy: select a message that is supposed to match but doesn't, click Item button on the OutlookSpy ribbon, select the SenderName property.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by tekoko10 Friday, May 13, 2016 6:08 AM
    Friday, May 13, 2016 4:07 AM

All replies

  • Hi tekoko,

    Based on your code, it seems you want to find mailItem by SenderName. How did you set value for naam? The value for naam must be equal to the SenderName of the mailItem you want, and the MailItem must be in Index folder. You could try the code below to get real SenderName.

    Debug.Print myItems.GetFirst().SenderName
    

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Marked as answer by tekoko10 Friday, May 13, 2016 6:08 AM
    Friday, May 13, 2016 3:30 AM
  • Are you sure you have the correct name? Keep in mind the sender name can include the email address as well - check using OutlookSpy: select a message that is supposed to match but doesn't, click Item button on the OutlookSpy ribbon, select the SenderName property.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by tekoko10 Friday, May 13, 2016 6:08 AM
    Friday, May 13, 2016 4:07 AM
  • yes that is it , i was confused with name and emailadres , now it works !

    Many thanks Dmitry Streblechenko _MVP_ and Edward Z

    Friday, May 13, 2016 6:10 AM