OL2002: Restrict May Not Work with Uncached Properties (292451)



The information in this article applies to:

  • Microsoft Outlook 2002

This article was previously published under Q292451

SYMPTOMS

You use the Restrict and IncludeRecurrences methods in the Outlook object model and Outlook appears to stop responding (hang), or the collection of items does not appear to be functioning correctly.

CAUSE

This may happen if all of the following are true:
  • You have items that recur and do not have an end date.
  • In the filter of the Restrict method, you did not specify an end date, so the number of items in the collection is infinite.
  • In the filter of the Restrict method, you used a property that Outlook does not cache by default.

RESOLUTION

Use one of the following workarounds:

  • Use the SetColumns method to cache the property you wish to use Restrict on. As an example, uncomment the SetColumns line in the "Steps to Reproduce the Problem" section below.
  • Alter the filter of the Restrict method so that the method will not return an infinite collection.

MORE INFORMATION

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:

Steps to Reproduce the Problem

  1. Create a new Calendar folder.
  2. Create three recurring appointments with a start date of 3/14/99.
  3. On two of the appointments, set the Mileage field to Test. The Mileage field does not appear on the default appointment form, but you can use the Field Chooser to add the field to a table view and then use the in-cell editing feature to set the value.
  4. With the Calendar folder selected, create a reference to the Microsoft Outlook 10.0 Object Library and run the following Visual Basic Automation code:
    Sub RestrictTest()
       Dim outapp As Outlook.Application
       Dim itms As Outlook.Items
       Dim itmsR As Outlook.Items
       Dim itm As Outlook.AppointmentItem
       Dim strQ As String
       Set outapp = New Outlook.Application
       Set itms = outapp.ActiveExplorer.CurrentFolder.Items
       itms.IncludeRecurrences = True
       itms.Sort "[Start]"
       strQ = "[Mileage] = 'test'"
       Set itmsR = itms.Restrict(strQ)
       'itmsR.SetColumns "Mileage"
       For Each itm In itmsR
          If itm.Start > #6/1/1999# Then Exit For
          Debug.Print itm.Subject & " : " & itm.Start & " : " & itm.Mileage
       Next
    End Sub
    					

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


Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbnofix kbprb KB292451