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. Se as propriedades personalizadas não forem definidas no item, a pesquisa falhará.

Consultas Jet

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'"

Consultas DASL

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:

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

where {GUID} is the following GUID:

{00020329-0000-0000-C000-000000000046}

Filtrando propriedades personalizadas referidas pelo namespace da cadeia de caracteres de MAPI

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.

Nota O especificador de tipo hexagonal deve ser do formulário 0000HHHHH com apenas 8 dígitos em vez de 9. Para obter mais informações sobre os especificadores de tipo hexagonal (HHHH) para vários tipos MAPI, consulte Tipos de Propriedade.

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) & "https://schemas.microsoft.com/mapi/string/" _ 
& "{00020329-0000-0000-C000-000000000046}/MyProperty"_ 
& "/0000001f" & Chr(34) & " = '12-74440'" 

Suporte e comentários

Tem dúvidas ou quer enviar comentários sobre o VBA para Office ou sobre esta documentação? Confira Suporte e comentários sobre o VBA para Office a fim de obter orientação sobre as maneiras pelas quais você pode receber suporte e fornecer comentários.