Datasheet

Designing Applications
39
14.Now close the macro window and choose Yes when prompted to save the macro you
have just created. Then change the frmCompany form to Form view and save the changes
you made to it. When you open the form in form view, there should be a navigation
button on it that allows you to move forward through the records in the form.
If you look at the button's properties, you will see that the name of the macro is listed in
the On Click property on the Event tab. This is how Access knows to run the macro when
the button is clicked. The macro name was inserted automatically into the event property
because you right-clicked the button to select Build Event... and the Click event is the
default event for buttons. If you had built the macro yourself, you could still make Access
use it whenever you click the cmdNext button, but you would have to insert the macro's
name manually into the On Click event property before it would work. We'll look at this
whole area in a lot more detail in the next chapter.
15.Finally, complete the form by adding navigation buttons to enable you to move to the
previous, first, last, and new records. You should be able to work out how to do this
simply enough by referring to the steps described above.
The Finished Product
So there we have it! Your own handcrafted navigation buttons! You can customize these further if
you wish you may want to change the caption on the Next button to add a 'greater than' sign
(>). You may even want to add a tooltip by modifying the ControlTipText property of each button.
You can also provide a hotkey for each of the buttons. This allows the user to activate the
button from the keyboard by pressing Alt and a particular letter. To set this up, you simply type
an ampersand (&) in the button's Caption property, before the letter that you want to activate
the button. So, for example, if you typed &Next the user could select the button by pressing Alt-
N. The hot key (in this case N) will appear underlined on the button.
Once you have added the other buttons, your form should look something similar to the one
shown overleaf: