VBA example - Microsoft Access: if else to animate letters


VBA if else to make words animate

In this example, you will learn If...Else...Statement of VBA conditional statement to make the letters to move from left to right. The example shows the phrase World Best Learning Center. When the form loaded and the timer run, the phrase World Best Learning Center will start to move from left to right and change its fore color every time. The figure below is the form to show moving letters.

VBA example - Microsoft Access If Else Statement Moving Letter VBA 

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

VBA example - Microsoft Access If Else Statement Moving 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 Name and Caption property Label control:

Caption: World Best Learning Center

Name: lblWBLC

Note: For a form have only one control, you can set or not set the control name. It's up to you. But if the form have more than one control, you should set the control name. It is easy for you when you call the control to use.

 

The following VBA code below explicates the example.

 

Option Compare Database

Dim ml As Integer

 

Private Sub Form_Load()

lblWBLC.FontSize = 30

TimerInterval = 500

ml = 0

End Sub

 

Private Sub Form_Timer()

If ml < Me.Width / 2 Then    ' If ml is less than the haft length of form

lblWBLC.Move ml   ' then move the phrase world best learning center

ml = ml + 500  ' Set the length of moving is equal to 500 for each moving

Else

ml = 0

End If

' Random the fore color of the caption label(World Best Learning Center)

lblWBLC.ForeColor = RGB(88 + (Rnd() * 155), 10 + (Rnd() * 255), 0)

End Sub



Comments

Achal comment

 Achal

no comments


2018-05-17
amir comment

 amir

dd


2016-07-14



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.