Color scheme: Light
You are here: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » Navigation and commands » WklButton » Build a command bar

Build a command bar

In this tutorial, you put a command bar in the header of a customer form: a primary command, a split button for saving, and a menu button for the view. You set up all three in the designer without code, and then add the event procedures that respond to them.

Prerequisites

  • Access in Microsoft 365 or the Access Runtime, 32-bit or 64-bit, with the WKL Forms Object Library 1.27 or later installed and registered for the current Windows user (How to: Install the released package).
  • A form bound to a table, for example frmCustomers based on tblCustomers.
  • Every WKL control opens its designer the same way: in Design view, open the property sheet (F4), select the Other tab, and click [...] in the Custom row (How to: Open the designer of a control).

Steps

1. Insert three buttons in the form header

Open frmCustomers in Design view, show the form header, and insert WKL Button three times (Form Design › Controls › ActiveX Controls). On the Other tab of the property sheet, name the buttons btnNew, btnSave, and btnView, and then set the background color of the form header.

2. Set up the primary command

Select btnNew, click [...] in the Custom row of the property sheet, and on the Button page set: kind Command button, caption &New, symbol E710, and style Primary command. On the Appearance page, set the background to the color of the form header.

3. Set up the split button

For btnSave: kind Split button, caption &Save, symbol E74E. On the Menu page, enter two rows:

KeyCaption
pdfSave as &PDF
xlsxSave as &Excel workbook

4. Set up the menu button

For btnView: kind Menu button, caption &View, style Subtle. On the Menu page, enter:

KeyCaptionGroupCheck mark
nameBy &Namesort✓
cityBy &Citysort

5. Respond to the events

Open the form's module and add:

Private Sub btnNew_Click()
    DoCmd.GoToRecord , , acNewRec
End Sub
 
Private Sub btnSave_Click()
    If Me.Dirty Then Me.Dirty = False
End Sub
 
Private Sub btnSave_MenuItemClick(ByVal Key As String)
    Select Case Key
        Case "pdf": DoCmd.OutputTo acOutputForm, Me.Name, acFormatPDF
        Case "xlsx": DoCmd.OutputTo acOutputForm, Me.Name, acFormatXLSX
    End Select
End Sub
 
Private Sub btnView_MenuItemClick(ByVal Key As String)
    Me.OrderBy = IIf(Key = "name", "Name", "City")
    Me.OrderByOn = True
End Sub

When the user chooses “By City” in the menu, the menu checks that entry and clears the check mark from “By Name” before MenuItemClick occurs, because both entries belong to the “sort” option group.

Expected result

In Form view, the header shows the three buttons with the Office look. New adds a record, the main part of Save saves it, its arrow opens the two export options, and View opens a menu with the checked sort order. Spacebar or Enter presses the button that has the focus, and Alt+Down Arrow or F4 opens a menu.

Next steps

en/wiki/msaccess/comctl/navigation-and-commands/button/tutorial.txt · Last modified: by Wolfgang van der Stille