Access Cookbook - Ken Getz [186]
Me.tglMark.Caption = "Save Place"
Case msDiscard
' Reset marked position
' and unpress button
svarPlaceHolder = Empty
Me.tglMark.Caption = "Save Place"
Me.tglMark.Value = False
Case Else
' Shouldn't happen
MsgBox "Unexpected value for intAction", _
vbCritical + vbOKOnly, "acbHandleMarkReturn"
End Select
End Function
To create a shortcut menu, select View → Toolbars Customize, make sure you are on the Toolbars tab in the dialog, and click the New button. Name your new pop-up menu popAbandon, as shown in Figure 9-11, and click OK. Note that this dialog is used for creating both toolbars and menus.
Figure 9-11. Creating a shortcut menu from the Toolbars tab of the Customize dialog
Click the Properties button in the Customize dialog, and select Popup for the type property. Click OK in the message box that appears, and click Close in the Toolbar Properties dialog.
Scroll down in the list of toolbars in the Customize dialog, and check Shortcut Menus. A special menu bar appears showing you all the shortcut menus. Click the down arrow next to Custom, the last menu item, and then click the right arrow next to popAbandon. This displays your blank shortcut menu as a small gray box.
In the Customize dialog, select the second tab, Commands. With the File category selected in the list on the left, click on Custom in the list of commands on the right, and drag a custom command over to your blank popAbandon menu, as shown in Figure 9-12.
Figure 9-12. Adding a custom item to a shortcut menu
Right-click on the new Custom item you created in your shortcut menu, and select Properties. In the Properties dialog, change the caption to &Abandon Saved Place. For the OnAction property, enter "=acbAbandonBookmark". Click the Close button in the Properties dialog, and click the Close button in the Customize dialog.
In the VBA editor, insert a new module and add this public function:
Public Function acbAbandonBookmark( )
Call Form_frmCustomer.acbHandleMarkReturn(3)
End Function
In the form, set the ShortcutMenuBar property of the tblMark button to popAbandon.
Save the form and verify that it works correctly. Mark a record to return to, move to another record, right-click on the button, and your pop-up menu will enable you to abandon the place you had saved.
To see how this works, load the 09-04.MDB database and open the frmCustomer form, which contains 500 customer records. Navigate to a record and begin to make a change to it. For example, in Figure 9-13, we made some edits to Margaret Woods's record before marking it. Click on the Save Place toggle button in the form's header to mark the current record and save your place in the recordset. The toggle button will remain depressed and its caption will change to Return to Saved Place (see Figure 9-14). Now navigate to some other record. Click on the toggle button again, and you will return instantly to the earlier "marked" record.
Figure 9-13. The frmCustomer form before marking the current record
Figure 9-14. The frmCustomer form after marking the current record
Mark the record again and navigate to yet another record. Perhaps this time you have changed your mind and wish to abandon the earlier marked record in favor of the current one. However, if you press the toggle button a second time, you will return to the previously marked record, losing your new place. You can remedy this situation by right-clicking while the mouse cursor is over the toggle button control. A shortcut menu giving you the option to abandon the previously marked record will appear (see Figure 9-15). Select this option, and you'll now be able to mark the current record instead.
Figure 9-15. The toggle button's shortcut (right-click) menu
Discussion
The mark-and-return facility built into the frmCustomer form has several interesting user interface aspects. First, the toggle button is the main user interface element. This control type is ideally suited for this situation because it is able to store binary state information that visually matches the