Microsoft KB Archive/264301

= PRB: OL98:Cannot Read Custom Properties Defined on DocumentItems =

Article ID: 264301

Article Last Modified on 3/4/2004

-

APPLIES TO


 * Microsoft Outlook 98 Standard Edition

-



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 &quot;Microsoft Outlook 9.0 Object Library.&quot; ' The code assumes that you have a Word document with a custom property ' called &quot;NextReviewer&quot; in your Inbox folder. Make sure that you assign a    value' to the &quot;NextReviewer&quot; 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(&quot;Outlook.Application&quot;) Set ns = ol.GetNamespace(&quot;MAPI&quot;) 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(&quot;NextReviewer&quot;) ' Add the custom property to the item as a User-defined field Set myprop = olDocItem.UserProperties.Add(&quot;NextReviewer&quot;, olText) ' Retrieve its current value. msgbox olDocItem.UserProperties (&quot;NextReviewer&quot;)

