This tip demonstrates how to search for data by name, data type, and geographic location; how to use the Catalog search engine to search an ArcSDE geodatabase; how to predefine search criteria and then show the Search dialog box; and how to start the search automatically.
You could use a macro like this to define and execute a search that you run periodically. Showing the dialog box lets you end the search at any time by clicking Stop.
How to use
- Paste this macro into VBA.
- Change the location where the search should begin.
- Run the macro.
Sub NameTypeExtent()
'create a new query object to define search criteria
Dim pQ As IQuery
Set pQ = New FileSystemQuery
'look for items whose name includes the text "contour"; this name is not derived from the
'item's metadata, if it exists. If DatasetName isn't set the search uses DatasetName = "*".
pQ.DatasetName = "*contour*"
'look for Shapefiles only
Dim pNT As INativeType
Set pNT = New GxFilterShapefiles
Set pQ.DatasetType = pNT
'look for items that describe an area within US coterminous states. NOTE: you can't
'predefine a geographic extent in the Search dialog box.
Dim pEnv As IEnvelope
Set pEnv = New envelope
pEnv.PutCoords -126, 24, -66, 50
Set pQ.envelope = pEnv
pQ.EnvelopeOperator = esriFindEnvelopeOperatorWithin
'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 uses metadata to evaluate
'dataset type and extent. If metadata doesn't exist, that information is instead
'derived directly from the GxObjects in the Catalog tree.
pSE.Enabled = True
'search an ArcSDE geodatabase. Must use Catalog engine to search
'geodatabases and GIS servers. Database connection names must include the
'.sde file extension. The Catalog tree must contain a connection to the database,
'though it may be disconnected.
Set pSEP = pSE
pSEP.LocationString = "Database Connections\my ArcSDE Connection.sde"
Case Else
'disable other search engines
pSE.Enabled = False
End Select
Next
'set the search criteria and then show the search dialog box
pFD.initialize pQ
pFD.Show True
'start the search automatically. Search criteria aren't derived from the dialog box unless
'you click Find Now.
pFD.DoSearch pQ
End Sub