Microsoft KB Archive/222482

From BetaArchive Wiki
Knowledge Base


OL2000: How to Handle Unexpected Items in a Collection

Article ID: 222482

Article Last Modified on 11/23/2006



APPLIES TO

  • Microsoft Outlook 2000 Standard Edition



This article was previously published under Q222482


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 the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

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 answers to commonly asked questions about Microsoft Outlook 2000 solutions, please see the following article in the Microsoft Knowledge Base:

146636 OL2000: Questions About Custom Forms and Outlook Solutions



Additional query words: OutSol OutSol2000 vbscript

Keywords: kbhowto kbprogramming KB222482