OL2002: How to Handle Unexpected Items in a Collection

Article translations Article translations
Article ID: 292062 - View products that this article applies to.
This article was previously published under Q292062
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

Summary

If you are using the Outlook object model to loop through items in a folder, you should make sure your solution will work even if the folder contains items that you might not expect to be there.

More information

Examples of items that you might unexpectedly find in a folder include:
  • A Meeting or Task Request item in the Inbox.
  • An item that is a file from an external source, such as a Microsoft Word document or a Microsoft Excel spreadsheet. These files may be directly posted into a folder from another application, or they may have been dragged into a folder.
  • A Conflict message sent by Microsoft Exchange, if more than one person has edited an item at the same time in a public folder.
  • An item that is based on a form designed using the Exchange Forms Designer (EFD). These types of items do not function exactly like Outlook items in all circumstances. For example, you cannot programmatically add an attachment that is a link to an EFD-based item.
  • A Distribution List item in a Contacts folder. These lists are stored in the default Contacts folder and have a message class of IPM.DistList.
The Inbox typically poses a concern since the user generally has less control over what items are placed in that folder. Also, Outlook fully introduces Distribution Lists into the Contacts folder.

NOTE: In Outlook 98 (using Internet Mail Only mode), these distibution lists could exist in the folder but were not visible through the user interface. They were created and stored by the Windows Address Book.

Typically you will not run into problems when your code references one of these items. Problems usually occur when you try to reference a property of a particular item type and that property does not exist.

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 The following are approaches you can use to avoid these types of problems. Choose the approach that is best suited to your solution, the type of folder you are working with, and the types of items that could potentially affect your solution.

  • Use the TypeName function to test the type of object being referenced.
    If TypeName(objMyItem) = "ContactItem" Then...
    					
  • Check the MessageClass property of an item.
    If Left(objMyItem.MessageClass, 11) = "IPM.Contact" Then...
    					
  • Use error trapping to simply skip over lines of code that may potentially cause a problem.
    For Each oMyMailItem in oMyInboxItems
       On Error Resume Next
       oMyMailItem.VotingOptions = ""
       oMyMailItem.Save
    Next
    					

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
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 292062 - Last Review: October 24, 2013 - Revision: 1.0
Applies to
  • Microsoft Outlook 2002 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto KB292062

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