PRB: OL98:Cannot Read Custom Properties Defined on DocumentItems (264301)



The information in this article applies to:

  • Microsoft Outlook 98

This article was previously published under Q264301

SYMPTOMS

You have a Microsoft Office document (for example, a Microsoft Word document or a Microsoft Excel document) that contains custom properties, and the document is kept as a DocumentItem object in a Microsoft Outlook folder. When you attempt to read the values of custom properties on the item using the Outlook Object Model, you cannot reach them.

RESOLUTION

To resolve this behavior, add the custom properties to the DocumentItem object as user-defined fields, and then read their values.

The following code sample demonstrates how to read the value of a custom property on a Word document that is located in your Inbox folder:
' Please paste the following code into a Microsoft Visual Basic project,
' and have a reference to the "Microsoft Outlook 9.0 Object Library."
' The code assumes that you have a Word document with a custom property
' called "NextReviewer" in your Inbox folder. Make sure that you assign a     value' to the "NextReviewer" property. For information on how to create
' custom properties on Word documents and how to move Word documents
' to Microsoft Outlook folders, please refer to the article in 
' the References section of this article.

    Dim ol As Outlook.Application
    Dim ns As Outlook.NameSpace
    Dim olDocItem As DocumentItem
    Set ol = CreateObject("Outlook.Application")
    Set ns = ol.GetNamespace("MAPI")
    Set InboxFolder = ns.GetDefaultFolder(olFolderInbox)
    Set olDocItem = InboxFolder.Items(1)

    ' The following line of code, if uncommented, will return the
    ' error message:

    ' Run-time error '91':
    ' Object variable or With block variable not set
    
    'msgbox olDocItem.UserProperties("NextReviewer")
    
    ' Add the custom property to the item as a User-defined field
    Set myprop = olDocItem.UserProperties.Add("NextReviewer", olText)
    ' Retrieve its current value.
    msgbox olDocItem.UserProperties ("NextReviewer")
    
				

REFERENCES

For additional information about creating custom properties on Word documents, and how to move Word documents to Microsoft Outlook folders, click the article number below to view the article in the Microsoft Knowledge Base:

180564 OL98: How to Display Word Custom Properties in Outlook


Modification Type:MinorLast Reviewed:3/4/2004
Keywords:kbMsg kbOutlookObj kbprb KB264301