Filter with an Associative Search Database

To use the filtering functionality for an Associative Search Database in script, the column that you are filtering must have its Filter setting selected in the Associative Search Database Properties window. The data records from the database can then be limited by applying a filter text so that only data records are use in the search that have that specific value.

For example, you have an Associative Search Database called "InvoiceVendors" that has the following columns:

  • Client

  • Vendor ID

  • Vendor Name

  • Etc...

Assuming that the field on the XDocument client contains the value that is applied for filtering. An example of the script is as follows:

Private Sub Document_BeforeLocate(ByVal pXDoc As CASCADELib.CscXDocument, ByVal LocatorName As String)
   If LocatorName = "DBLoc" Then
      SetFilterOnClient(pXDoc.Fields.ItemByName("Client").Text)
   End If
End Sub

Private Sub SetFilterOnClient(strClient As String)
   Dim strFilterColumn As String
   strFilterColumn = "Client"
   Dim strFilterText As String
   strFilterText = strClient
   
   Dim database As CscAssociativeSearchDatabase
   Set database = Project.Databases.ItemByName("InvoiceVendors").AssociativeSearch

   database.ClearFilterAttributes()
   database.AddFilterAttribute strFilterColumn, strFilterText

   On Error GoTo 0

lbl_Error:
   Err.Clear
   On Error GoTo 0
End Sub

On the script sheet where the above code is placed, an additional reference is needed. Refer to the Cedar Associative Search Engine Library.