Farbschema: Riviera
Sie befinden sich hier: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Narrow a list with filter chips

How to: Narrow a list with filter chips

Open a list that's already narrowed down for a purpose, such as „certificates that expire within 14 days“ reached by clicking a key figure on the start page, show the user why the list is shorter, and let them remove that condition with a single click.

Requires WKL Forms Object Library 1.45 or later.

Solution overview

  • A filter chip is a named WHERE condition. WklGrid.AddFilterChip(Name, Caption, Condition) narrows down the records; the grid applies (Filter) AND (chip 1) AND (chip 2) ..., both in memory and in server mode.
  • The filter bar shows it. Below the records, each chip appears as a „Caption ✕“ button. Clicking it, pressing Delete on it, or invoking it with a screen reader removes the chip, and the records are read again.
  • The application is notified. FilterChipRemoved(Name, ByUser) reports every removal, so a heading or a key figure can follow along.
  • The start page passes the reason. A WklKpiCard with a Key raises Click(Key); the shell shows the list page and adds the chip that belongs to that key.

Implementation

In the module of the shell form frmShell (with the start page card kpiExpiring, Key = "expiring", and the page subform sfPage):

Option Compare Database
Option Explicit
 
Private Sub kpiExpiring_Click(ByVal Key As String)
    Me!sfPage.SourceObject = "frmCertificates"
    With Me!sfPage.Form!grdCertificates.Object
        .ClearFilterChips
        Select Case Key
            Case "expiring"
                .AddFilterChip "expiring", "expires within 14 days", "Expiry Between Date() And Date() + 14"
            Case "locked"
                .AddFilterChip "locked", "locked", "Status = 'Locked'"
        End Select
    End With
End Sub

In the module of the page form frmCertificates:

Private Sub grdCertificates_FilterChipRemoved(ByVal Name As String, ByVal ByUser As Boolean)
    If ByUser Then Me!lblHeading.Caption = "All certificates"
End Sub

Remarks

  • A chip with an existing name replaces that chip in place, and the bar keeps its order. RemoveFilterChip raises FilterChipRemoved with ByUser = False; ClearFilterChips doesn't raise anything.
  • Filter remains the application's own condition and doesn't include the chips. A JPath filter ($...) can't be combined with chips and is rejected while chips are set.
  • Chips require a RecordSource; a grid bound only to a Recordset (for example, on a UserForm) rejects them.
  • Chips aren't saved with the form or in the remembered column arrangement, so set them each time the page is opened for a purpose.
  • Clear filter in the bar removes the user's column filters, not the chips.
  • ShowFilterBar = False hides the bar; the chips still apply, but the user can't remove them.
en/wiki/msaccess/comctl/how-to/narrow-a-list-with-filter-chips.txt · Zuletzt geändert: von Wolfgang van der Stille