Build a navigation shell
In this tutorial, you build a shell form with a WklNavBar on the left and a page subform that
fills the rest, both arranged by a WklDockLayout. You design the entries without code, a single
event procedure swaps the page, and a badge shows a count. It takes about fifteen minutes.
Prerequisites
- Access in Microsoft 365 or the Access Runtime, 32-bit or 64-bit, with the WKL Forms Object Library 1.24 or later installed and registered for the current Windows user (How to: Install the released package).
- A new database in a trusted location.
- 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. Create a table and two pages
Run these lines one at a time in the Immediate window (Ctrl+G):
CurrentDb.Execute "CREATE TABLE tblCustomers (CustomerID COUNTER PRIMARY KEY, Company TEXT(50), City TEXT(50))"
CurrentDb.Execute "INSERT INTO tblCustomers (Company, City) VALUES ('Adams Supply', 'Boston')"
CurrentDb.Execute "INSERT INTO tblCustomers (Company, City) VALUES ('Baker Tools', 'Chicago')"
Select tblCustomers in the Navigation Pane and choose Create › Form; save the form as
frmCustomers. Choose Create › Blank Form, add a label that says „Welcome,“ and save the
form as frmStart. These are the pages the shell shows.
2. Lay out the shell
Create a form in Design view, set Default View to Single Form, set Record Selectors and
Navigation Buttons to No, and save the form as frmShell. In the Detail section:
- Choose Form Design › Controls › ActiveX Controls, select WKL Navigation Bar, click OK, and draw the control along the entire left edge, about 2.5 in. wide. Name it
navMain. - Draw a subform control over the rest of the section, name it
sfPage, and set its Source Object toForm.frmStart. - Insert a WKL Dock Layout the same way, draw it over both controls, name it
Layout1, and choose Arrange › Send to Back.
Leave the anchors of navMain and sfPage at Top Left. In the property sheet for Layout1,
select the Other tab, click [...] in the Custom row, and on the Areas page check that
the layout found navMain (Left) and sfPage (Fill); then click OK.
3. Design the entries
Select navMain and click [...] in the Custom row of the property sheet. On the Entries
page:
- Click Entry. In the fields below the list, set Key to
startand Caption toHome, then click Choose … next to Symbol, typehouse, and press Enter. Turn on Selected on opening. - Click Group, and set Key to
dataand Caption toData. - With the group selected, click Entry: Key
customers, CaptionCustomers, symbolpeople(search forpeople). - Click Entry again, set Key to
settings, Caption toSettings, and the symbol togear, and then choose At the bottom edge under Place.
The preview shows the bar both expanded and as the icon column. Click OK and save the form.
4. Swap the page in Navigate
Open the form's module (Form Design › View Code) and add:
Private Sub navMain_Navigate(ByVal Key As String)
Select Case Key
Case "start": Me!sfPage.SourceObject = "Form.frmStart"
Case "customers": Me!sfPage.SourceObject = "Form.frmCustomers"
Case "settings": MsgBox "Settings"
End Select
End Sub
Private Sub Form_Load()
' Badges are run-time values: set them whenever the form opens.
Me!navMain.Object.SetBadge "customers", DCount("*", "tblCustomers"), wskInfo
End Sub
5. Use the shell
Open frmShell in Form view and try the following:
- Click Customers. The page shows the customers, and the entry is highlighted.
- Click the toggle button (three lines) or press Ctrl+B. The bar collapses to the icon column and the page gets wider; do it again, and the bar expands. Ctrl+B also works while a field on the page has the focus.
- Drag the splitter bar between the navigation bar and the page; the expanded bar gets wider.
- Press Tab to move to the bar, then use the arrow keys and Enter.
- Close the form and open it again. The mode and width are just as you left them.
Expected result
A shell whose page changes with the entry the user chooses, a bar that switches between captions
and icons and remembers each user's choice, a badge with the number of customers, and no code
except the Navigate procedure and the badge.
Next steps
- How to: Fill the navigation bar from a table: the same shell without the
Navigateprocedure, with the entries and pages kept in a table