RefreshScopes Method

Refreshes the list of currently available ScopeFolder objects.

expression.RefreshScopes

*expression   * Required. An expression that returns one of the objects in the Applies To list.

Example

The following example displays all of the currently available ScopeFolder objects on the C:\ drive in the My Computer scope and demonstrates the need for the RefreshScopes method when changes to the folder list occur.

Sub TestRefreshScopesMethod()
' Displays what happens before and after the RefreshScopes
' method is called when a new folder is added to the list
' of scope folders.

    ' List before the folder is created.
    Call ListFolderNames
    
    ' Create a new folder on the C:\ drive in My Computer.
    ' An error will occur if this folder already exists.
    MkDir Path:="C:\Delete_After_Using"
    
    ' List after the folder is created.
    ' The newly-created folder does not appear in the list.
    Call ListFolderNames
    
    ' Refresh the list of folders.
    Application.FileSearch.RefreshScopes
    
    ' The newly-created folder now appears in the list.
    Call ListFolderNames
    
End Sub

Sub ListFolderNames()

    Dim i as Integer
    Dim strResults As String
    
    ' Loop through all the top-level folder names on the C:\ drive
    ' in My Computer and report the results.
    ' .SearchScopes.Item(1) = "My Computer"
    ' .ScopeFolders.Item(2) = "C:\"
    With Application.FileSearch.SearchScopes.Item(1). _
        ScopeFolder.ScopeFolders.Item(2)
        
        For i = 1 To .ScopeFolders.Count
            strResults = strResults & .ScopeFolders. _
                Item(i).Name & vbCrLf
        Next i
        
        MsgBox "Folder Names on C:\...." & vbCrLf & strResults
    
    End With
    
End Sub

Applies to | FileSearch Object