_Application.AdvancedSearch(String, Object, Object, Object) Method

Definition

Performs a search based on a specified DAV Searching and Locating (DASL) search string.

public Microsoft.Office.Interop.Outlook.Search AdvancedSearch (string Scope, object Filter, object SearchSubFolders, object Tag);
Public Function AdvancedSearch (Scope As String, Optional Filter As Object, Optional SearchSubFolders As Object, Optional Tag As Object) As Search

Parameters

Scope
String

The scope of the search. For example, the folder path of a folder. It is recommended that the folder path is enclosed within single quotes. Otherwise, the search might not return correct results if the folder path contains special characters including Unicode characters. To specify multiple folder paths, enclose each folder path in single quotes and separate the single quoted folder paths with a comma.

Filter
Object

The DASL search filter that defines the parameters of the search.

SearchSubFolders
Object

Determines if the search will include any of the folder's subfolders.

Tag
Object

The name given as an identifier for the search.

Returns

A Search object that represents the results of the search.

Remarks

You can run multiple searches simultaneously by calling the AdvancedSearch method in successive lines of code. However, you should be aware that programmatically creating a large number of search folders can result in significant simultaneous search activity that would affect the performance of Outlook, especially if Outlook conducts the search in online Exchange mode.

The AdvancedSearch method and related features in the Outlook object model do not create a Search Folder that will appear in the Outlook user interface. However, you can use the Save(String) method of the Search object that is returned to create a Search Folder that will appear in the Search Folders list in the Outlook user interface.

Using the Scope parameter, you can specify one or more folders in the same store, but you may not specify multiple folders in multiple stores. To specify multiple folders for the Scope parameter, use a comma character between each folder path and enclose each folder path in single quotes. For default folders such as Inbox or Sent Items, you can use the simple folder name instead of the full folder path. For example, the following lines of code represent valid Scope parameters:

Dim Scope As String = "'Inbox', 'Sent Items'" string Scope = "'Inbox', 'Sent Items'";

Dim Scope1 As String = "'" & Application.Session.GetDefaultFolder( _
    Outlook.OlDefaultFolders.olFolderInbox).FolderPath & _
    "','" & Application.Session.GetDefaultFolder( _
    Outlook.OlDefaultFolders.olFolderSentMail).FolderPath
string Scope1 = "'" + Application.Session.GetDefaultFolder( 
    Outlook.OlDefaultFolders.olFolderInbox).FolderPath + 
    "','" + Application.Session.GetDefaultFolder( 
    Outlook.OlDefaultFolders.olFolderSentMail).FolderPath;

The Filter parameter can be any valid DASL query. For additional information on DASL queries, see Filtering Items and Referencing Properties by Namespace. Note that you cannot use a JET query for the Filter parameter of Advanced Search. If Instant Search is enabled on a store that contains a folder specified in the Scope parameter, you can use Instant Search keywords to improve the performance of your search. If you use Instant Search keywords and Instant Search is not enabled, Outlook will return an error and your search will fail.

Applies to