Introduction
A form with lively objects—such as animated command buttons, GIFs, or moving text—makes working with MS Access applications more interesting for the user. However, MS Access does not provide these features out of the box. To create dynamic elements, we must rely on our imagination and ingenuity, using the standard tools available in Access.
After working with MS Access for a while, I grew tired of repeatedly using the same static objects in application designs. I wanted to create something more eye-catching to make the experience more engaging. As the saying goes, “Necessity is the mother of invention.” This led me to develop several creative features, including:
- Command button animation
- Animated floating calendar
- Office Assistant in message boxes
- Animated labels for search results
- Reminder ticker, and more.
Today, we will learn a simple label animation technique using an example from the Employees form in the Northwind.mdb
sample database.
Import the following objects from the Northwind sample database.:
- Table: Employees
- Form: Employees
If you open the Employees form in Normal View, you’ll see that the employee’s full name—firstname and lastname combined—is displayed in the form header within a text box. When you navigate to a different record, the full name in the header updates automatically.
We will enhance this by adding an animated effect, making the employee name appear character by character, moving slowly from the right edge of the label to the left, and finally settling into place.
Open the Employees Form in Design View.
Delete the existing TextBox that displays the Employee's Name.
Create a Label on the Header of the Form.
Display the Property Sheet (View -> Properties) of the Label and change the following Property Values:
- Name = lbl1
- Width = 3.5"
- Height =0.32"
- Back Style = Transparent
- Border Style = Transparent
- ForeColor = 16777215
- Font Name = Times New Roman
- Font Size = 18
- Font Weight = Bold
- Text Align = Right
Display the Code Module of the Form (View ->Code).
Press Ctrl+A to highlight the existing VBA Routines and press the Del key to delete them.
Copy the following VBA Code and paste it into the Code Module of the Form.
Label Animation Code.
Option Compare Database Option Explicit Dim txt1 As String, txtlen As Integer Dim j As Integer, txt2 As String Private Sub Form_Timer() j = j + 1 If j <= txtlen Then txt2 = Left(txt1, j) Me.lbl1.Caption = txt2 'Me.lbl2.Caption = txt2 Else Me.TimerInterval = 0 End If End Sub Private Sub Form_current() txt1 = UCase(Me![FirstName] & " " & Me![LastName]) txtlen = Len(txt1) j = 0 Me.TimerInterval = 50 End Sub
Save and Close the Employees Form.
Open the Employees Form in the normal view.
Click the forward Navigation records button to move the records one by one.
The names of the employees will be displayed in the same style by moving from the right edge of the label to the left.
When you open the form, the employee name will gradually move into place from right to left, appearing character by character in the header label.
Fancy Work to the Label.
We will add a little fancy work to the Employee Name for a three-dimensional backlit effect by copying the Label and placing it over the existing one. See the finished design of the image given below:
Open the Employee Form in Design View.
Select the header label.
Click on the Copy, Paste ToolBar buttons to make a copy of the label (or select Copy, Paste Options from the View Menu).
Click on the new Label to select it if it is not in the selected state.
Display the Property Sheet of the Label (View ->Properties).
Change the following Property Values as shown below:
- Name = lbl2
- ForeColor = 128
Move the label up and over the first label and place it slightly down from the top edge of the first label and to the left, about the thickness of a hair. The sample image design view is given below:
While the Form is still in design view, display the VBA Module (View ->Code)
You will find the following line of code in the Sub Form_Timer() Event Procedure in a different color (most probably in green color):
Find the ' (single quote) character at the beginning of this line and delete it.
Save and Close the Form.
Open the Form in the Normal View.
Now you will find the Employee Names appearing in animated characters, with the 3D effect, as shown in the second image above.
I have already included the line of code necessary to run this trick. All you have to do is enable that line in the VBA code, do the following:
'Me.lbl2.Caption = txt2
This is my first time visit to your blog and I am very interested in the articles that you serve. Provide enough knowledge for me. Thank you for sharing useful and don't forget, keep sharing useful info: à¸à¸™ิเมะ An animation is defined as a visual change in a scene with respect to time.
ReplyDelete