Find and Restrict are methods of the
MAPIFolder.Items collection that can be used
to return a single item or a collection,
respectively, that meet the search criteria.
Dates as strings
not date literals
When using a date to
search with the Find or Restrict method, the date in the search string
must be formatted as an unambiguous string, not a date literal, and
must contain only years, months, days, hours, and minutes -- no
seconds.
This is an example of a valid search string for all appointments
begin on or after 24 Oct 2002:
[Start] <= "October 24, 2002 12:00 AM"
To make it easier to build such strings that contain internal
quotation marks, I recommend using the following Quote function:
Assuming you already have an colItems collection from a calendar
folder, the code to build and apply the above search string would
look like this:
No seconds allowed
When working with a date from a variable or an Outlook property,
you must apply formatting to the value to eliminate the seconds
element that is intrinsic to any date/time variable or property.
The easiest way to do such formatting in VB or VBA is the
Format() function, along with the "ddddd" date format. For example, this expression returns the current
date/time in your locale's short date format plus the time without any seconds
element:
Format(Now + 1, "ddddd hh:mm AMPM")
The Format() function is not available in VBScript, however. In
many cases, you can use the FormatDateTime() function,
concatenating the date and time elements:
Alternatively, keeping in mind that users in different countries
may reverse the order of day and month in short date formats, you
may want to use a format that spells out the month, so that it is
completely unambiguous. If you want an unambiguous date with the month spelled
out, you can build it from the individual date/time
components:
Recurring items
The Items collection for a calendar folder includes only the
master instance of any recurring items. If you want to search for
individual recurrences, you must add these statements before your
Find or Restrict statement:
|