Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/201074

From BetaArchive Wiki
Knowledge Base


Programming with EntryIDs and StoreIDs in Outlook 2000

Article ID: 201074

Article Last Modified on 1/9/2006



APPLIES TO

  • Microsoft Outlook 2000 Standard Edition



This article was previously published under Q201074

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 (Vbaoutl9.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.

Each Outlook item (contacts, messages, appointments, and such) has a field called EntryID, which is a unique ID field generated by the messaging storage system for use with the MAPI folders that store the item.

Important The EntryID field may change if an item is moved to a different folder. This behavior will vary depending on the type of store. In a Microsoft Exchange mailbox, for example, "move" operations are implemented as a "copy and delete" operation. Therefore, a new item is created and therefore the item will have a new EntryID.

However, in a personal folders (.pst) file, moving an item to a new folder will not cause a new EntryID (unless an item in the Drafts folder is sent. In this case, the item in the Sent Items folder will have a new EntryID).

Each MAPI folder has a field called StoreID, a unique ID field for that particular folder. Each folder also has an EntryID field.

When using the GetItemFromID method to retrieve an item based on its MAPI IDs, you typically need to specify both the EntryID of the item and the StoreID of the folder. Using the EntryID of the 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. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

REFERENCES

For more information about available resources and answers to commonly asked questions about Microsoft Outlook 2000 solutions, click the following article number to view the article in the Microsoft Knowledge Base:

146636 Frequently asked questions about custom forms and Outlook solutions



Additional query words: OutSol OutSol2000 OL2K OL2000

Keywords: kbhowto kbprogramming kbcode KB201074