Barvna shema: Temna
Trenutno dejavna stran: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Switch a view with segments

How to: Switch a view with segments

Offer the periods „Day,“ „Week,“ and „Month“ side by side on a list form, like the view switchers in Office, and filter the form's records by the chosen period.

Requires WKL Forms Object Library 1.27 or later.

Solution overview

A WklButton of kind wbkSegment shows its segments (AddSegment) side by side; one of them is selected (SelectedKey), and the user's choice raises Change. The segments and the selection you set in Design view are saved with the form, so no code is needed to set them up; Change only applies the filter.

Implementation

In the designer ([...] in the Custom row), set the kind to Segments, the caption to „Period“ (the name screen readers announce), and on the Segments page enter the rows day / Day, week / Week, and month / Month, with Chosen set for day. Then add this code:

Private Sub Form_Load()
    ApplyPeriod Me!btnPeriod.Object.SelectedKey
End Sub
 
Private Sub btnPeriod_Change()
    ApplyPeriod Me!btnPeriod.Object.SelectedKey
End Sub
 
Private Sub ApplyPeriod(ByVal period As String)
    Select Case period
        Case "day": Me.Filter = "OrderDate = Date()"
        Case "week": Me.Filter = "OrderDate >= Date() - Weekday(Date(), 2) + 1"
        Case "month": Me.Filter = "Year(OrderDate) = Year(Date()) And Month(OrderDate) = Month(Date())"
    End Select
    Me.FilterOn = True
End Sub

Remarks

  • Change doesn't occur when code sets SelectedKey; that's why Form_Load applies the filter itself.
  • Clicking the selected segment changes nothing, just as in an option group. With MultiSelect, each segment toggles on and off; read SelectedKeys in that case.
  • The keyboard reaches the segments with a single tab stop; the Left Arrow and Right Arrow keys select the neighboring segment.
  • Disable a segment with SegmentEnabled; the keyboard skips it.
en/wiki/msaccess/comctl/how-to/switch-a-view-with-segments.txt · Zadnja sprememba: uporabnika Wolfgang van der Stille