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 option 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.
It has columns such as:
-
Client
-
Vendor ID
-
Vendor Name
-
Etc...
The Client column is configured for filtering in the database properties. A database locator is configured to use that database for vendor searches, and the database is configured to be used with a database lookup button.
Assuming that the field on the XDocument Client contains the value that will be 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 ValidationForm_ButtonClicked(ByVal ButtonName As String, ByVal pXDoc As CASCADELib.CscXDocument)
If ButtonName = "DBLookupVendors" 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 supplierSettings As SCBCdrSupExSettings
Set supplierSettings = Project.Databases.ItemByName("InvoiceVendors").AssociativeSearch.SCBCdrSupExSettings
On Error GoTo lbl_Error
supplierSettings.ClearFilterAttributes()
supplierSettings.AddFilterAttribute strFilterColumn, strFilterText
On Error GoTo 0
lbl_Error:
Err.Clear
On Error GoTo 0
End Sub