Outlook - Unable to set EntryID to an object from another inbox

Asked By Pete Bradshaw on 25-Mar-13 07:55 AM

Hi guys,

I have a problem with this piece of code.

The full code checks attachments to see if they are zipped or pasted pictures and works fine when using my own inbox.

If I try this on another inbox that I have full permission to, I get an "-2147220991    [MAPI - [MAPI_E_UNKNOWN_ENTRYID(80040201)]]" message.

This is the code I'm using:-

  Dim objSession As Object
  Dim objItm As Outlook.MailItem
  Dim oMsg As Object
  Dim strEntryID As String

  Set objSession = CreateObject("MAPI.Session")
    'Log onto session
      objSession.Logon , , False, False
     
    Set objItm = GetCurrentItem()

  'Get mail items ID
    strEntryID = objItm.EntryID
  
'#BREAKS HERE!!!
  'Use item ID to set oMsg
    Set oMsg = objSession.GetMessage(strEntryID)


Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
     
    Set objApp = CreateObject("Outlook.Application")
    On Error Resume Next
    Select Case TypeName(objApp.ActiveWindow)
      Case "Explorer"
        Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
      Case "Inspector"
        Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
      Case Else
        ' anything else will result in an error, which is
        ' why we have the error handler above
    End Select
   
    Set objApp = Nothing
End Function

Does anybody have any ideas?

Many thanks

Pete