Color scheme: Dark
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » WKL Forms Object Library how-to guides » How to: Build a side bar with cards

How to: Build a side bar with cards

Show several subforms in one place in a WklDockLayout (for example, a side bar on the right with “Properties” and “Notes” cards) and let the user switch between them with tabs, just like in an Office task pane.

Requires WKL Forms Object Library 1.37 or later.

Solution overview

Areas with the same group in Panes (Name=Zone:Group) form a tab group: they share one place in their zone below a tab strip, and one card is shown at a time. The group is resized, collapsed, and dragged as a single area. PaneCaption sets the text of a tab, GroupPane reads or sets the card that's shown, and AfterTabChange reports every switch (made by the user, by code, or when the form opens with the user's remembered card), so a form can load a card's content in one place.

Implementation

  1. In Design view, draw the side bar's subforms (sfProps and sfMemo) on top of each other at the right edge of the layout; the size and position come from the first card.
  2. Open the layout's designer ([...] in the Custom row), go to the Areas page, and enter the cards with the same group: zone Right, group Side, and the tab text in the Tab column (Properties, Notes). The preview shows the tab strip, and the card shown lists all the cards. Click OK and save the form.

To do the same in code:

' Design view of frmAdmin is open.
With Forms!frmAdmin!Layout1.Object
    .Panes = "lstCustomers=Left; sfProps=Right:Side; sfMemo=Right:Side; sfMain=Fill"
    .PaneCaption("sfProps") = "Properties"
    .PaneCaption("sfMemo") = "Notes"
End With

Load a card's content when it's shown, and load the first card when the form opens:

Private Sub Form_Load()
    ' The card shown when the form opens raises no AfterTabChange (Access's tab control raises no
    ' Change either): load it here.
    LoadCard Me!Layout1.Object.GroupPane("Side")
End Sub
 
Private Sub Layout1_AfterTabChange(ByVal Group As String, ByVal Pane As String, ByVal Reason As Long)
    ' Every switch: chosen by the user (wtcUser), by code - GroupPane, Reset, Layout - (wtcCode),
    ' or the user's remembered card restored when the form opened (wtcRestore).
    LoadCard Pane
End Sub
 
Private Sub LoadCard(ByVal pane As String)
    If pane = "sfMemo" And Me!sfMemo.SourceObject = "" Then Me!sfMemo.SourceObject = "frmMemo"
End Sub

Remarks

  • The card shown when the form opens (the group's first card, or the user's remembered card if that's the first one) doesn't raise AfterTabChange. Only a remembered card other than the first one is reported, with wtcRestore. Code that loads cards on demand must therefore also load the shown card in Form_Load, or that card stays empty.
  • BeforeTabChange occurs only for the user; set Cancel to keep the current card, for example while a record on it can't be saved. Setting GroupPane in code raises AfterTabChange (wtcCode) but not BeforeTabChange.
  • If the old card has the focus, switching moves the focus to the new card, because Access won't hide the control that has the focus. Leaving a subform saves its changed record, just like clicking in another subform; if the table rejects the record, Access shows its message.
  • All cards in a group need the same zone; a group can also fill the remaining space (Fill). The tab strip sits at the top of the group's space and uses the system colors, so high contrast follows the Windows settings.
  • Keyboard: the tab strip is a tab stop of the layout, before the group's splitter bar. The Left Arrow and Right Arrow keys show the neighboring card, and Home and End show the first and last cards. UI Automation exposes a Tab named after the group, with one TabItem per card. Ctrl+Tab isn't used, because inside a subform Access uses it to leave the subform.
  • The card that's shown is part of the user's arrangement (AutoSaveLayout) and comes back the next time the form opens; Reset returns every group to its first card and reports each group that switches with wtcCode.
en/wiki/msaccess/comctl/how-to/build-a-side-bar-with-cards.txt · Last modified: by Wolfgang van der Stille