Microsoft Access 2010 Bible

(Rick Simeone) #1

Chapter 19: Advanced Access Form Techniques


689



  1. Embed a picture on the form.

  2. Set the TimerInterval property of the form to 100.


The value represents the number of milliseconds between firing of the event.



  1. Assign the following event procedure to the Timer event:


Private Sub Form_Timer()
‘Move the image down and to the right.
ctlImage.Left = ctlImage.Left + 200
ctlImage.Top = ctlImage.Top + 100
End Sub

Screen positions in VBA are given in twips —^1 ⁄ 1 ,440 inch (^1 ⁄ 567 centimeter). This event procedure
moves the image in the ctlImage control down and to the right on the form every^1 ⁄10th of a second.

The frmAnimation form in Chapter19.accdb uses the technique described here to move an
airplane bitmap across the form. A couple of other techniques are used to create a bit of animation.
The following event procedure, associated with the Timer event, causes a bitmap of a pencil
eraser to move back and forth by manipulating the Image control’s PictureAlignment prop-
erty. The procedure also causes a globe to spin by using the Visible property of three different
bitmaps that are positioned one on top of the other:

Private Sub Form_Timer()
On Error Resume Next
‘Wiggle the eraser:
If Eraser.PictureAlignment = 2 Then
Eraser.PictureAlignment = 3
ElseIf Eraser.PictureAlignment = 3 Then
Eraser.PictureAlignment = 4
ElseIf Eraser.PictureAlignment = 4 Then
Eraser.PictureAlignment = 3
End If
‘“Spin” the globe:
If World1.Visible = -1 Then
World1.Visible = 0
World2.Visible = -1
ElseIf World2.Visible = -1 Then
World2.Visible = 0
World3.Visible = -1
ElseIf World3.Visible = -1 Then
World3.Visible = 0
World1.Visible = -1
End If
‘Now move the plane:
Plane.Left = Plane.Left + 200
Plane.Top = Plane.Top + 100
If Plane.Left > 9000 Then
Plane.Left = 0
Plane.Top = 1440
End If
End Sub
Free download pdf