Queries must be formatted properly.
- String values must be enclosed between quotes. For example,
[CompanyName] = "Microsoft".
- int/long/enum values must not be enclosed between quotes. For example,
[Importance] = 1.
- date/time values must be in 24 hr format. For example,
[End] = "05/10/1961 20:30".
A restriction match requires that the item include a value for the property. For example, if you do not set the e-mail address for a contact, the contact cannot be found by using the restriction string [Email1Address]<>someone@example.com even though "no address" is a logical match for "not someone@example.com."
Use IPOutlookItemCollection::FindNext to find subsequent items in a collection that pass the restriction.
Parenthesizeing a restrict query has the effect of causing the query to be evaluated from right-to-left, as opposed to left-to-right. For example, the two queries below yield different results. The only difference is the usage of parenthesis.
Query 1:
[Categories] = "Health" AND [SourceId] = "16" OR [Subject] = "Water"
Query 2:
( ( [Categories] = "Health" AND [SourceId] = "16") OR [Subject] = "Water" )
You can create complex queries. For example:
"[Categories] = \"Business\" AND [Categories] <> \"Personal\""
You can create locale specific date queries. For example:
GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &stForLocale, NULL, szLocaleSpecificStartTime, TEMP_BUFFER);
GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stForLocale, NULL, szLocaleSpecificStartDate, TEMP_BUFFER);
StringCchPrintf(szRestrict, ARRAYSIZE(szRestrict), L"[Start] >= \"%s %s\" ", szLocaleSpecificStartDate, szLocaleSpecificStartTime);
hr = pItems->Restrict(szRestrict, &pItems2);