Search notes:

Outlook Object Model: applying filters

A filter is used to search for item objects that match the criteria that are set forth in the filter.

Jet and DASL filters

A filter is formulated either with JET or DASL syntax.
JET DASL
A DASL filter always starts with @SQL=". (In VBA, an apostrophe can be embedded into a string by doubling it: filter = "@SQL=""…""").
Boolean queries [Unread] = true "@SQL=""urn:schemas:httpmail:read"" = 0"
Starts-with queries Not possible "@SQL=""urn:schemas-microsoft-com:office:office#Keywords"" ci_startswith 'Partner'"

Methods that accept filters in their arguments

Outlook's Object Model allows to specify a filter in the following methods:
Method JET Filter Support DASL Filter Support Comment
application.advancedSearch No Yes
folder.getTable Yes Yes
items.find Yes Yes Using query keywords ci_phrasematch or ci_startswith result in errors
items.restrict Yes Yes
search.getTable No Yes
table.findRow Yes Yes Using query keywords ci_phrasematch or ci_startswith result in errors
table.restrict Yes Yes
view.filter No Yes

Search in mail body

option explicit

sub searchInMailBodies(searchText as string) ' {

   dim fld as folder
   set fld = session.getDefaultFolder(olFolderInbox)

   dim DASL_query as string
   DASL_query = "@SQL=""urn:schemas:httpmail:textdescription"" ci_phrasematch '" & searchText & "'"

   dim tbl as table
   set tbl = fld.getTable(DASL_query)

   dim r as row
   do until tbl.endOfTable
      set r = tbl.GetNextRow
      debug.print r("Subject")
   loop

end sub ' }
Github repository about-MS-Office-object-model, path: /Outlook/_filter/search-in-mail-body.vb

See also

Outlook Object Model

Index