OL2002: Programming with EntryIDs and StoreIDs

Article translations Article translations
Article ID: 293152 - View products that this article applies to.
This article was previously published under Q293152
Expand all | Collapse all

On This Page

SUMMARY

This article provides an overview and example of using an item's EntryID and StoreID fields as part of an Outlook solution using the Outlook object model.

MORE INFORMATION

A common use of the GetItemFromID method is to create a link or relationship from one Outlook item to another. The Outlook Visual Basic Help file (Vbaol10.chm) documents this method.

An example of when you might want to use the GetItemFromID method is if you created contact items for all members of a family instead of just having one contact item for the head of the household. You might want to create a custom contact form so you can create "links" between all members of the family. This could be in the form of a list box on the custom contact form that automatically includes a list of other members of the family. Using the custom form, when you select a person from the list, their contact item automatically appears.

In a solution like this, you would typically create the links between the contact items by storing the related IDs with each contact. So each contact item might have 20 user-defined fields that store the IDs of up to 20 related contacts. Microsoft Visual Basic Scripting Edition (VBScript) code uses these IDs to retrieve the names of the other family members in order to populate the list and to retrieve the other contact item when the user selects a name from the list.

Overview Item IDs

Each Outlook item (contacts, messages, appointments, and such) has a field called EntryID, which is a unique ID field generated by the MAPI message store, such as a Personal Folders file (.pst), and Exchange Server mailbox, or a public folder store on an Exchange Server. This ID is assigned by the store when an item is saved.

Important The EntryID field may change if an item is moved to a different folder. This means that if you plan to develop a solution that is based on using the EntryID field as a unique identifier, you must not import the items, export the items, or move the items to a different folder. Otherwise, the EntryID field may change. This behavior varies depending on the type of store. For example, in an Exchange mailbox, move operations are implemented as copy and delete operations. Therefore, a new item is created and the new item will have a new EntryID. However, in a Personal Folders file (.pst), moving an item to a new folder will not result in a new EntryID unless an item in the Drafts folder is sent. If an item in the Drafts folder is sent, the item in the Sent Items folder will have a new EntryID.

Items also have a property containing the StoreID, but the Outlook object model does not expose this property. However, you can access this property if you are using MAPI programming technologies.

Overview of Folder IDs

Each MAPI folder has both a StoreID and EntryID. The StoreID represent the ID of the store, and therefore all folders within the same store have the same StoreID. The EntryID for a folder behaves exactly like the EntryID field for an item. It is also consistent as long as the folder remains within a store, but changes if a folder is moved to a different store.

Using the GetItemFromID Method

When using the GetItemFromID method to retrieve an item based on its MAPI IDs, you typically need to specify both StoreID and the EntryID so that Outlook can locate the individual item. Since items do not have StoreID fields, you must obtain the StoreID from the folder in which the item is located. Note that using the EntryID of a folder instead of the StoreID will generate an error, which may vary depending on the type of folder you are working with.

If an item is not found, you receive error number -2147221233 (0x8004010F), which corresponds to MAPI error code MAPI_E_NOT_FOUND.

The following is a Visual Basic for Applications automation example that illustrates the use of the GetItemFromID method. The code retrieves the StoreID from the default Contacts folder, fills an array (MyEntryID) with the EntryIDs for all of the contacts in the folder, and finally retrieves a specific contact item.
Sub OutlookEntryID()

   ' The Outlook object library must be referenced.
   Dim ol As Outlook.Application
   Dim olns As Outlook.NameSpace
   Dim objFolder As Outlook.MAPIFolder
   Dim AllContacts As Outlook.Items
   Dim Item As Outlook.ContactItem
   Dim I As Integer

   ' If there are more than 500 contacts, change the following line:
   Dim MyEntryID(500) As String
   Dim StoreID As String
   Dim strFind As String

   ' Set the application object
   Set ol = New Outlook.Application

   ' Set the namespace object
   Set olns = ol.GetNamespace("MAPI")

   ' Set the default Contacts folder.
   Set objFolder = olns.GetDefaultFolder(olFolderContacts)

   ' Get the StoreID, which is a property of the folder.
   StoreID = objFolder.StoreID

   ' Set objAllContacts equal to the collection of all contacts.
   Set AllContacts = objFolder.Items
   I = 0

   ' Loop to get all of the EntryIDs for the contacts.
   For Each Item In AllContacts
      I = I + 1
      ' The EntryID is a property of the item.
      MyEntryID(I) = Item.EntryID
   Next

   ' Randomly choose the 2nd Contact to retrieve.
   ' In a larger solution, this might be the index from a list box.
   ' Both the StoreID and EntryID must be used to retrieve the item.
   Set Item = olns.GetItemFromID(MyEntryID(2), StoreID)
   Item.Display

End Sub
				
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs.
If you have limited programming experience, you may want to contact a Microsoft Certified Partner or Microsoft Advisory Services. For more information, visit these Microsoft Web sites:

Microsoft Certified Partners - https://partner.microsoft.com/global/30000104

Microsoft Advisory Services - http://support.microsoft.com/gp/advisoryservice

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Differences When Accessing EntryIDs using MAPI or CDO

If you use the Collaboration Data Objects (CDO) object model or other MAPI programming technologies to access the EntryID of an item, you may find that the ID does not match the ID that returned by the Outlook object model. The Outlook object model always returns the long-term EntryID, whereas CDO and MAPI often return the short-term EntryID. To obtain the long-term EntryID using CDO, use one of the following approaches:

  • Retrieve the CdoPR_ENTRYID property in the Message object's fields collection.
  • Use the Update method of a CDO message (item) and then the ID property will return the long-term EntryID.
For additional information about accessing ID properties using MAPI, click the article number below to view the article in the Microsoft Knowledge Base:
252649 HOWTO: Open a MAPI IMessage Interface with CDO Entry ID

REFERENCES

For additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:
287530 OL2002: Questions About Custom Forms and Outlook Solutions

Properties

Article ID: 293152 - Last Review: November 23, 2006 - Revision: 4.4
APPLIES TO
  • Microsoft Outlook 2002 Standard Edition
  • Microsoft Collaboration Data Objects 1.0
  • Microsoft Collaboration Data Objects 1.0a
  • Microsoft Collaboration Data Objects 1.1
  • Microsoft Collaboration Data Objects 1.2
  • Microsoft Collaboration Data Objects 1.21
Keywords: 
kbhowto KB293152

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com