How to: Edit records beside the list
When the user picks a record, open an edit form in a panel to the right of the list, without a dialog box and without leaving the list.
Requires WKL Forms Object Library 1.48 or later.
Solution overview
Place a WklDrawer between the list and a subform control. Content names the subform control,
Open shows a form in it, and Close hides it again. The edit form is an ordinary Access form;
the drawer only positions it. Filter it to the record in AfterOpen or through the subform
control's link fields.
Implementation
In Design view, put the list on the left and a subform control named sfEdit on the right, then
draw a WKL Drawer (Form Design › Controls › ActiveX Controls) as a narrow bar in
the gap and name it drw1. In the designer ([...] in the Custom row, Drawer page),
select sfEdit as the Content; the preview names the controls that become narrower.
Private Sub lstCustomers_DblClick(Cancel As Integer)
Me!drw1.Object.Open "frmCustomerEdit"
End Sub
Private Sub drw1_AfterOpen(ByVal SourceObject As String)
' The content is loaded now: show the chosen record.
Me!sfEdit.Form.Filter = "CustomerID = " & Me!lstCustomers
Me!sfEdit.Form.FilterOn = True
End Sub
Private Sub drw1_BeforeClose(ByVal Reason As Long, Cancel As Integer)
' Keep the panel open while the record there has unsaved changes.
If Me!sfEdit.Form.Dirty Then Cancel = True
End Sub
Different contents can each have their own width:
With Me!drw1.Object
.Widths = "{""frmCustomerEdit"": 4500, ""frmOrderMatrix"": 9000}"
.MinBeside = 3402 ' 6 cm of the list stay visible
.CloseOnEscape = True ' Esc in an unchanged record closes the panel
End With
Remarks
- The
ReasonofBeforeCloseandClosedis aWklDrawerCloseReason:wdcCode(Close,Toggle, or a newOpen),wdcUser(the close button, or Enter or Spacebar on the bar), orwdcEscape. - Setting
Widthin code doesn't raiseAfterResize; only dragging, an arrow key, or UI Automation does, and only those widths are remembered for the user (AutoSaveLayout). - Leave the anchors of the list and the subform control set to Top Left: the drawer calculates every arrangement from the designed positions. Anchors inside the content form are fine; with
AnchorContent, the drawer applies them. - Design the content form without a horizontal scroll bar and no wider than its narrowest use: Access lets a form grow at run time, but not shrink.
- While the record in the content has unsaved changes, Esc does what it normally does in Access (it undoes the change); only Esc in an unchanged record closes the panel.