VBA example - Microsoft Access: if else to animate words

VBA if else animate words

In this example, you will learn the VBA conditional statement to make the animation of letters. The example shows the phrase Happy New Year!. When the form loaded and the timer run, the phrase Happy New Year! will start to show from one character to the end of this phrase. This example uses Timer event to make the letters animate. The figure below is the form to show animate letters.

VBA example - Microsoft Access If Else Statement Letter Animation VBA 

 To make the animate letters, you have to create a form as figure:

VBA example - Microsoft Access If Else Statement Design Form

The form has only one label control. To create the form, you have to follow the steps:

- Create a form in Form Design

-  Drag and drop a Label control on the form.

-  Set caption property Label control:

Caption: Happy New Year!

The following VBA code below explicates the example.


Option Explicit

Option Compare Database

Dim i As Integer

Dim ca As String


Private Sub Form_Load()

i = 0

ca = Me.lblhppnewyear.Caption

Me.TimerInterval = 700

lblhppnewyear.FontSize = 35

End Sub


Private Sub Form_Timer()

If i < Len(ca) Then

i = i + 1

Me.lblhppnewyear.Caption = Left(ca, i)

Else: i = 0

End If

' Assign multi color to the word Happy New Year! by randomizing the colors

Me.lblhppnewyear.ForeColor = RGB(50 + CInt(Rnd() * 200), 90 + CInt(Rnd() * 100), 0)


End Sub


Note: Whenever you want to make something animate based on the computer timer, Timer event is used. Put the code to make something animate in the form's Timer event procedure and set TimerInterval in the form's Load event procedure. The Timer can run in a duration of time according to its TimerInterval property. If you set TimerInterval is small the animation run fast and vice versa. The unit of TimerInterval is millisecond; if you set 1000 to TimerInterval, it is equal to one second.


meshack comment




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.