Article ID: 293152 - View products that this article applies to.
This article was previously published under Q293152
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.
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 IDsEach 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 IDsEach 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 MethodWhen 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.
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 CDOIf 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:
(http://support.microsoft.com/kb/252649/EN-US/ )HOWTO: Open a MAPI IMessage Interface with CDO Entry ID
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:
(http://support.microsoft.com/kb/287530/EN-US/ )OL2002: Questions About Custom Forms and Outlook Solutions
Article ID: 293152 - Last Review: November 23, 2006 - Revision: 4.4
Contact us for more help
Connect with Answer Desk for expert help.