In this example, you will learn VBA For... Next Loop Statement to make pictures animate according to the timer. The example illustrates a form that has the pictures arranged as a heart like the figure above.
To have a form as the figure above, you must have a picture and create the form in Form Design. See as the figure below:
Note: Unselect Use Control Wizards before you drag the image control to the form.
Then apply the VBA Code below:
Option Explicit
Option Compare Database
Private Sub Form_Load()
TimerInterval = 100
DoCmd.Maximize
Dim cnt As Control
Dim i As Integer
Dim L As Integer
Dim T As Integer
For i = 0 To Controls.Count - 1
Set cnt = Controls.Item(i)
L = cnt.Left
T = cnt.Top
cnt.Move L + 4500, T + 1500
Next
End Sub
Private Sub Form_Timer()
' Display animate heart
Dim i As Integer
i = 0
For i = 0 To Controls.Count - 1
Dim X As Control
Set X = Me.Controls.Item(i)
' Set flower1 picture to all image controls
X.Picture = CurrentProject.Path & "\flower1.jpg"
Next
End Sub
0 comments:
Post a Comment