Chapter 22 Animation
Chapter 22 Animation
B
elieve it or not, it is possible to animate objects in Access. By taking this possibility
to an extreme, you can write a complete arcade game in Access—all the tools to
do this are there. Serious users of Access would probably not be very impressed to
find Space Invaders appearing in their database, but it can be done. However, for the purposes
of this book, you will simply move a label object about on a form so it bounces around the
borders of the form. This is rather reminiscent of the famous arcade game Breakout.
You first need to create a form for the purpose of a container for your animation. Click
Create in the Access menu bar and then click the blank form icon in the Forms group of the
ribbon. Close the Field List pane that appears on the right-hand side of the window and click
the View drop-down in the Views group of the ribbon.
Change the view to Design View by clicking Design View on the drop-down. Next, click
the Label icon on the Controls group of the ribbon. Move your cursor anywhere on the form
and hold the left mouse button down to drag a label shape. Once you have dragged your label
shape onto the form, right-click the Label control and select Properties in the pop-up menu.
Change theNameproperty to My Label and theCaptionproperty to something you wish
to display, such asMy Text. Change theFontSizeproperty to 18 (enlarging the Label box to
accept this if necessary).
Your form in Design view should look like Figure 22-1.
Click your cursor anywhere on your form (not on the Label box) and right-click the
mouse. Select Build Event and choose Code Builder to take you into the VBE window for
your form. Add the following code:
Private Sub Form_Open(Cancel As Integer)
Dim VIncr As Long, HIncr As Long, Spd As Integer
Spd = 15
VIncr = Spd
273