ItemProperty.Value returns Automation Object Error RRS feed

  • Question

  • Hi all,

    This is a good one. So, I have an application that is NOT an addin for Outlook. It uses the Outlook Object Model to access an Outlook mailbox. I am simply trying to get basic information about an Email out of Outlook and into another database system. The system and code is not Microsoft based which makes things a little harder, but basically I am using an old version of Visual Basic (think VB6 era).

    So, I developed the application and all works fine. I can grab values from an email message, such as Subject, SenderName, SenderEmailAddress, Body, Location, etc. Installed the application at a client site and it doesn't work! Other sites it does, it appears to be this one only (so far anyway).

    The issue is that some items cannot be retrieved. Some properties, such as SenderName, are valid, but I cannot access their Value. The ItemProperty.Name, Class and Type all return valid values. In this case, SenderName, 99 and 1 respectively, but when I access the .Value the program returns an Automation Object Error. This happens for the body as well, but not the Subject.

    I'm inclined to think that the client has something installed, but just wanted to ask if anyone has seen this issue before.


    Thursday, September 13, 2012 7:20 AM

All replies

  • The error may be caused by a difference between the version of the Outlook Object Model (.olb) file you are referencing vs. what is actually deployed. You need to develop against the earliest version of Outlook that you want to support and compile with that library referenced.

    That's just a guess though, as the SenderName property has been around since at least Outlook 2000.  However, SenderEmailAddress is only available in Outlook 2003 and later.

    Eric Legault MVP (Outlook)
    About me...
    Try Outlook Appins - affordable and easy to use!

    Thursday, September 13, 2012 3:10 PM
  • Please show your code.

    Does the error happen with all items or just some of them?

    Dmitry Streblechenko (MVP)
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Thursday, September 13, 2012 4:47 PM
  • The Version of Outlook is 2010 btw.

    The code is really basic. The application is in Lotus Notes, so therefore this is coded in LotusScript, which is basically VB6.

    Sub ProcessOutlookEmail (olitem As Variant )
    On Error GoTo ErrrorHandler
    	Dim NewEmailDocument As NotesDocument
    	Dim AttachmentItem As Variant
    	Dim olAttachmentList As Variant
    	Dim olattachment As Variant
    	Dim iCount As Integer, i As Integer
    	Dim sFileName As String
    	Dim uoFile As New FileSystem
    	Dim Session As New NotesSession
    	Dim RelatedDocsItem As NotesRichTextItem
    	Set NewEmailDocument = g_ThisDatabase.Createdocument
    	Call NewEmailDocument.ReplaceItemValue ( "Form", "Imported Email")
    	Call NewEmailDocument.ReplaceItemValue ( "EmailSubject", olitem.Subject)
    	Call NewEmailDocument.ReplaceItemValue ( "fld$Sender", olitem.SenderName)
    	Call NewEmailDocument.ReplaceItemValue ( "DateSent", olitem.CreationTime )
    	Call NewEmailDocument.ReplaceItemValue( "Body",  olitem.Body )
    ...'Lots of other code here that doesn't apply.
    End Sub

    So olitem is a variant that represents a OOM MailItem object. Its .class property returns 43 which is correct. The call to olitem.SenderName fails. If commented out, the next failure occurs on olitem.Body. The other items work.

    To further debug the issue, I added this into the code:

    Forall Item in olitem.ItemProperties
    If Item.Name = "SenderName" Then
       MsgBox Item.Name
       MsgBox Item.Class
       MsgBox Item.Type
       MsgBox Item.Value
    End If

    The for loop was just used for investigations, but I ended up with the following. The results were that the Item SenderName exists, its name is "SenderName" as expected, the Class is 99, the Type is 1 and when I go to access Value, I get the error occur. Interestingly if I perform the same on the item "Subject", the Class and Type values are the same and the Value returns a string as expected.

    Further to this, I executed scripts via Outlook Spy to make sure it could access the problem properties, and sure enough it can.

    Chances are high here that Notes is obscuring any useful errors from me and just returns is own "207 Automation Object Error", but the fact remains that accessing the Value portion of particular Items, in this particular environment is throwing an error. So far the only Items I know of that throw the error are SenderName, SenderEmailAddress and Body.

    I was hoping that someone would pop in and say "oh thats because of this, do that", but that doesn't appear to be the case. :(


    PS: I should just add that the test computer has valid AV that appears as Valid according to Outlook, so this should prevent any Address Book and Send Email popup warnings from appearing. 
    • Edited by Paul Thorne Friday, September 14, 2012 1:25 AM Added PS
    Friday, September 14, 2012 1:20 AM
  • Can you not declare the Outlook object variables explicitly?  Instead of "olitem As Variant", can you use "olitem As Outlook.MailItem"?

    Eric Legault MVP (Outlook)
    About me...
    Try Outlook Appins - affordable and easy to use!

    Friday, September 14, 2012 4:18 PM
  • Due to the code being written in LotusScript, no I am unable to do that. Nor am I able to browse the object properties when debugging.
    Sunday, September 16, 2012 11:36 PM
  • I can't be much help given that I don't have access to a LotusScript environment.  All I can suggest is to try and add better error handling if you can.

    Could it be possible that the Outlook items are corrupt somehow?  Does the error recur on the same items?

    Eric Legault MVP (Outlook)
    About me...
    Try Outlook Appins - affordable and easy to use!

    Monday, September 17, 2012 12:19 AM
  • Hi Paul,

    Eric & Dmitry's question about the code failing on all items vs. a subset is a great question and one that should be addressed up-front. That will likely indicate whether it's a code issue or a data issue. The key differences to look for in your customer's environment is e-mail account type, cached mode vs. online mode (if Exchange), mail message format, whether the offline address book is deployed (if specific to recipient properties), and probably most importantly, if there are any other add-ins or third-party solutions that are also touching the items in any way.

    Overall, I know it sounds like it won't matter here, but best practice is to not prefix variables with "ol" since that is what Outlook uses for constants in the object model. Over the years (but not recently), I've seen some crazy code logic issues where weird things happen. Plus, it also makes the code less readable. I'd really recommend using "o" or "obj" for object variable prefixes just to be safe.

    Also, I would suggest creating a short VBS file using the object model to see if you can reproduce the problem using that. It would be good to try to take your code out of the picture to help simplify things. That would also mean you'd be in a "fully supported" scenario from the Microsoft perspective :)

    But in all reality, if this solution is working fine with other customers of yours, that almost certainly indicates that this particular customer has something in their environment that's causing it.

    Another good question to ask is whether or not these machines are images. If so, the customer should ideally try installing everything from source media onto a clean machine/VM and test your solution with that.

    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Wednesday, September 26, 2012 1:40 PM