Access Cookbook - Ken Getz [185]
=HandleStateClick("Wyoming")
Create the function called in Step 5. This function can be either in the form's module (as we have created) or in a global module. It's up to you to decide what to do with the information passed to the function. In the sample form, the name of the state is passed to an unbound text box. The HandleStateClick function is shown here:
Private Function HandleStateClick(strState As String)
Me.txtChosenState = strState
End Function
Discussion
Because each button has its Transparent property set to Yes (which is very different from having its Visible property set to No!), it's still active. You can click on transparent buttons and they can react to events. Each transparent button corresponds to some physical region on the bitmap, so you can have the buttons' Click event procedures react according to their location on the bitmap. If only Windows supported irregularly shaped command buttons!
The size of the bitmap is key to the effectiveness of this technique. If you lay out the buttons all over the bitmap and then decide to resize it, your buttons' locations will no longer be correct. Make sure that you've fixed the size of the bitmap before you start laying out buttons. Although you can select all the buttons and resize them as a group, this is not a perfect solution.
Don't spend too much time getting the transparent buttons placed exactly. On the example form, the buttons' placement is fairly precise, but that works only because most of the states in the west are generally rectangular (you'll notice that there's no eastern seaboard on the map). Users will typically click in the center of the region, so covering each pixel on the edge isn't a serious concern.
9.4. Mark a Record on a Form and Return to It Later
Problem
Sometimes you are interrupted when you're editing a record on a form and need to move quickly to some other record. You'd like a way to save your place and easily return to it later. Is there an easy way to do this in Access?
Solution
Access forms have a Bookmark property that is similar to the bookmark you use when you put a book down but want to be able to quickly return to where you left off. This solution shows how to use VBA code to store the bookmark value of a particular record and return to it, presenting this functionality to your users with a toggle button. The solution also shows you how to add a custom shortcut menu to a control.
Follow these steps to add the ability to return to a designated record in your own forms:
Create a new bound form or open an existing form in design view. Add a toggle button (not a command button) control to the form's header or footer section. In the frmCustomer sample form, we named our button tglMark and added it to the header section.
Create an event procedure attached to the Click event of the toggle button. (If you're unsure of how to do this, see How Do I Create an Event Procedure? in the preface of this book.) Add the following code to the event procedure:
Me.Private Sub tglMark_Click( )
' If toggle button is depressed, then
' mark this record; otherwise return
' to previously saved record.
If Me.tglMark Then
Call acbHandleMarkReturn(msMark)
Else
Call acbHandleMarkReturn(msReturn)
End If
End Sub
Add the following code to the declarations area at the top of the code associated with your new form. This enumeration supplies all the possible values of the state of the marked row:
Public Enum MarkState
msMark = 1
msReturn = 2
msDiscard = 3
End Enum
Add the following public function to the form's module:
Public Function acbHandleMarkReturn(msAction As MarkState)
Static svarPlaceHolder As Variant
Select Case msAction
Case msMark
' Mark record position
svarPlaceHolder = Me.Bookmark
Me.tglMark.Caption = "Return to Saved Place"
Case msReturn
' Return to marked position
Me.Bookmark = svarPlaceHolder
svarPlaceHolder = Empty