I wanted to use Outlook 2003 "Search Folders" to search for Tasks.  I've got Outlook Tasks arranged in a hierarchy of folders, and sometimes I want to see all Tasks, regardless of folder.

This ought to be easy, but Search Folders are heavily biased toward email.  If you want a Search Folder for Tasks, you have to create it using VBA resembling:

Set MyOutlookApplication = Outlook.Application
SearchSubFolders = True
Set MapiNamespace = Application.GetNamespace("MAPI")
Set TasksFolder = MapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks)
Scope = "'" & TasksFolder.FolderPath & "'" ' #############################################################
Filter = "urn:schemas:tasks:Completed <> True"
Set Search = MyOutlookApplication.AdvancedSearch(Scope, Filter, SearchSubFolders)
ResultsFolderName = "All Tasks"
Set ResultsFolder = Search.Save(ResultsFolderName)

But using "urn:schemas:tasks" as a filter crashes Outlook.  The problem is that it isn't a valid schema.  So how do you discover valid schemas?  I Googled all over the place and didn't find a list, but there is a way to get Outlook to show you valid search schemas.

First, you have to customize your Outlook toolbar:

  1. Right-click on the main toolbar, select Customize, and then the Commands tab.
  2. Select the View category, and scroll Commands almost all the way down to the "Filter" command.
  3. Drag and drop Filter onto your toolbar or menu. (I put mine at the bottom of the View menu.)

Next, click on the top-level Tasks folder and then select Filter (from wherever you dropped it per the instructions above).

  1. Enter the criteria for your search, but do not press OK.
  2. Select the SQL tab.  You will be shown the magic incantation, including the schema, that you can assign to Filter in the code snippet above.
  3. Note that in order to Copy/Paste the query, you must select the "Edit these criteria directly" first.   (I recommend un-checking it after you Copy.)

For example, to search for Tasks that are incomplete, use the following Filter:

Filter = """http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/811c000b"" <> 1"

Near as I can tell, you have to quote the URL with a full quote mark (") and not an apostrophe (').