Filtering a Custom Field

You can specify custom properties in filters using Microsoft Jet syntax or DAV Searching and Locating (DASL) syntax. The custom properties must be defined in the folder where you are applying the filter. If the custom properties are only defined in the item, the search will fail.

Jet Queries

Custom properties can contain spaces in the property name. In a Jet query, as in all property name references, simply enclose the custom property name in square brackets. For example, the following Jet query retrieves all contacts where the custom property named "Preferred Gift" is exactly "Diamonds". For the query to succeed, the custom property named "Preferred Gift" has been defined in the folder that contains the custom contact items:

criteria = "[Preferred Gift] = 'Diamonds'"

DASL Queries

In a DASL query, if the name of a custom property contains spaces, you must apply Uniform Resource Locator (URL) encoding to each space character and replace the space with "%20". In general, URL encoding applies the same way to characters in a DASL query as in a URL.

When you construct a DASL query for a custom property, you must use the namespace GUID for Outlook custom properties in the following format:

http://schemas.microsoft.com/mapi/string/{GUID}/PropertyName

where {GUID} is the following GUID:

{00020329-0000-0000-C000-000000000046}

Filtering Custom Properties Referenced by the MAPI String Namespace

If the custom property you are filtering for does not exist in the UserDefinedProperties collection for the folder, and if you are referencing the custom property by the MAPI string namespace, then you must explicitly append a type specifier to the namespace representation of the custom property. Note that you need to specify the type only when applying a DASL filter to search and filter entry points in the Items collection and the Table object, and to the Application.AdvancedSearch method.

Bb147591.vs_note(en-us,office.12).gif  Note
The hexagonal type specifier must be of the form 0000HHHH with only 8 digits as opposed to 9. For more information on the hexagonal type specifiers (HHHH) for various MAPI types, see "MAPI Property Type Specifiers" below.

For example, if you want to use Items.Restrict to search for the custom Unicode string property named "MyProperty" and this property does not exist in the UserDefinedProperties collection for the folder, you must append the Unicode string type specifier, 0000001f, to the representation of the property in the MAPI string namespace:

criteria = "@SQL=" & Chr$(34) & "http://schemas.microsoft.com/mapi/string/" _
& "{00020329-0000-0000-C000-000000000046}/MyProperty"_
& "/0000001f" & Chr(34) & " = '12-74440'"

MAPI Property Type Specifiers

MAPI Property TypeHex ValueOLE Variant TypeDescription
PT_BINARY0102 VT_BLOBBinary (unknown format)
PT_BOOLEAN 000BVT_BOOLBoolean
PT_CLSID0102VT_CLSIDOLE GUID
PT_CURRENCY 0006VT_CY8-byte integer (scaled by 10,000)
PT_DOUBLE0005VT_R88-byte real (floating point)
PT_ERROR000AVT_ERRORSCODE value; 32-bit unsigned integer
PT_FLOAT0004VT_R44-byte real (floating point)
PT_LONG0003VT_I44-byte integer
PT_NULL 0001VT_NULLNull (no valid data)
PT_OBJECT000DVT_UNKNOWNData object
PT_SHORT0002VT_I22-byte integer
PT_STRING8001E or 001FVT_BSTRString
PT_SYSTIME0040VT_DATE8-byte real (date in integer, time in fraction)



Tags :


Page view tracker