How to set the criteria in the search dialog box


This tip demonstrates how to set the background map in the Geography tab of the Search dialog box; how to use the Catalog search engine to search a shared folder on the network; and how to predefine search criteria and dialog box properties and then show the Search dialog box.
You could use a macro like this to define basic criteria that you often use in a search. For example, set a background map of Europe, name the search "Europe services", and set the search to look for ArcIMS services; each time you open the dialog box with that macro you might search a different geographic area. Click Find Now in the dialog box to run the search.

How to use

  1. Paste this macro into VBA.
  2. Change the location where the search should begin.
  3. Run the macro.
[VBA]
Sub SetCriteriaInDialog()
    
    'create a new query object to define search criteria
    Dim pQ As IQuery
    Set pQ = New FileSystemQuery
    
    'set the data to be used as the background map. The path must indicate where to find the
    'data in the Catalog tree, and it must include file extensions even if they are hidden in
    'ArcCatalog, e.g., "c:\data\anImage.img" or "c:\data\aGdb.mdb\fClass". For ArcSDE, the
    'connection must include the file extension .sde, such as
    '"Database Connections\connection.sde\user.database.fClass". Below is an example for
    'using an ArcIMS service. Once the background map has been set, it won't change until
    'it is set to something else.
    Dim pFDS As IFindDialogSettings
    Set pFDS = pQ
    pFDS.BackgroundMap = "GIS Servers\Geography Network Services hosted by ESRI\ESRI_Satellite"
    
    'get the Search dialog box object, then get the available search engines
    Dim i As Integer
    Dim pFD As IFindDialog
    Dim pSE As ISearchEngine
    Dim pSEP As ISearchEngineProperties
    Set pFD = New FindDialog
    For i = 0 To (pFD.GetNumSearchEngines - 1)
        Set pSE = pFD.getSearchEngine(i)
        Select Case pSE.Name
            
            Case "Catalog"
                'enable the Catalog search engine. This engine examines GxObjects in the Catalog
                'tree and uses its properties or its metadata to evaluate the search criteria.
                pSE.Enabled = True
                
                'search a shared folder on a network disk. The Catalog tree must contain a folder,
                'database, or GIS server connection that accesses the search location.
                Set pSEP = pSE
                pSEP.LocationString = "\\aComputer\shareName\folderName"
                
            Case Else
                'disable other search engines
                pSE.Enabled = False
                
        End Select
    Next
    
    'set the search criteria in and properties of the search dialog box, and then show it
    pFD.initialize pQ
    pFD.Show True
    
End Sub