VBA example - Microsoft Access: if else to animate picture

VBA if else make pictures animate

In this example, you will learn the VBA conditional statement in changing the size of picture. The example demonstrates the changes of picture size from small to medium, and large like the figure:

 VBA example - Microsoft Access If Else Statement vba

The picture changes its size based on the computer time. When the timer runs, the picture will change its size. So to make the pictures active, firstly, you must have one picture. Secondly, you have to create a form as figure below:

VBA example - Microsoft Access If Else Statement form

The form has three Image controls. To create the form, you have to follow the steps below:

- Create a form in Form Design

-  Drag and drop three Image controls on the form.

-  Set Size Mode property Image control:

Size Mode: Stretch

Finally, follow the VBA code below:


Option Compare Database

Dim i As Integer


Private Sub Form_Load()

Me.TimerInterval = 1000

i = 0

End Sub


Private Sub Form_Timer()

If i = 0 Then

Image1.Visible = True

Image1.Picture = CurrentProject.Path & "\image1.jpg"

Image2.Visible = False

Image3.Visible = False


i = 1

ElseIf i = 1 Then

Image2.Visible = True

Image2.Picture = CurrentProject.Path & "\image1.jpg"

Image1.Visible = False

Image3.Visible = False


i = 2

ElseIf i = 2 Then

Image3.Visible = True

Image3.Picture = CurrentProject.Path & "\image1.jpg"

Image1.Visible = False

Image2.Visible = False


i = 0

End If


End Sub


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.