Edit records in a panel beside the list
In this tutorial, you build a customer list whose records open in a panel on the right: a double-click opens the edit form next to the list, the user can drag the panel wider, and the close button or Esc closes it again. It takes about ten minutes.
Prerequisites
- Access in Microsoft 365 or the Access Runtime, 32-bit or 64-bit, with the WKL Forms Object Library 1.48 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 the sample table
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')"
2. Create the edit form
Create a form bound to tblCustomers with the text boxes Company and City, each about 2.5 in.
wide. Set the Horizontal Anchor of both text boxes to Both, so that they follow the width
of the panel. Set Scroll Bars to Neither and save the form as frmCustomerEdit.
3. Lay out the list and the panel
Create an unbound form named frmCustomers and stay in Design view. In the Detail section, place:
| Control | Name | Where | Settings |
|---|---|---|---|
| List box | lstCustomers | on the left, about 4 in. wide and 2.5 in. tall | Row Source tblCustomers, Bound Column 1, Column Count 3 |
| Subform | sfEdit | to the right of the list, about 2.75 in. wide, as tall as the list | Source Object frmCustomerEdit |
Leave a small gap (about 0.1 in.) between them, and leave the anchors of both at Top Left.
4. Insert the drawer
Choose Form Design › Controls › ActiveX Controls, select WKL Drawer, click OK,
and draw the control as a narrow bar (about 0.08 in.) in the gap, as tall as the list. Name it
drw1.
5. Choose the content in the designer
Select drw1, open the property sheet, select the Other tab, and click [...] in the
Custom row. On the Drawer page, select sfEdit as the Content. The status line names
lstCustomers as the control next to the drawer, and the preview shows the list, the bar, and the
panel. On the Behavior page, turn on Esc closes. Click OK and save the form.
6. Open the panel from the list
Open the form's code module and add:
Private Sub Form_Load()
Me!drw1.Object.Close
End Sub
Private Sub lstCustomers_DblClick(Cancel As Integer)
Me!drw1.Object.Open "frmCustomerEdit"
End Sub
Private Sub drw1_AfterOpen(ByVal SourceObject As String)
Me!sfEdit.Form.Filter = "CustomerID = " & Me!lstCustomers
Me!sfEdit.Form.FilterOn = True
End Sub
7. Try it
Switch to Form view. The list takes up the whole width. Double-click Baker Tools: the list becomes narrower, and the panel shows the Baker Tools record, with the focus in it. Drag the bar to the left; the panel gets wider and the text boxes follow. Press Esc, and the panel closes. Close the form, open it again, and double-click a customer: the panel opens at the width you dragged it to.
Expected result
A list that opens each record in a panel next to it, at the width the user chose last, with the edit form's anchors applied, and that closes with the × on the bar or with Esc.
Next steps
- How to: Edit records beside the list: widths per content, limits, and canceling.