Label Animation Style-1
A Form with lively Objects like Animated Command Buttons or Animated Giffs or Moving Text etc. makes it more interesting to the User to work with our MS-Access Applications. MS-Access doesn't have any of those things built-in or ready made to use it quickly. Our imagination and ingenuity is the only tool available to create something with the existing, strictly for business like, features provided in MS-Access.
After working with MS-Access for sometime I got bored with whatever we have in MS-Access. I wanted to make something more eye-catching to kill the boredom. As the saying goes "Necessity is the father of inventions", I have invented and developed some of the interesting features like: Command Button Animation, Animated Floating Calendar, Usage of Office Assistant in MsgBoxes, Animating Label on search success and others.
Today we will learn a simple Label Animation Technique with an example on the Employees Form from Northwind.mdb sample database.
- Import the following objects from C:\Program Files\Microsoft Office\Office11\samples\Northwind.mdb sample database.:
- Table: Employees
- Form: Employees
If you open the Employees Form in Normal View you can see that the Employee's; Name; Firstname and Lastname joined together; is displayed on the Header of the Form in a Text Box. When you make some other record current on the Form the employee's full name changes on the Form Header Textbox as well.
We will add some animated effect to this and make the employee name appear slowly from right edge of the label to the left, character by character, and move 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
- Fore Color = 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 high-light the existing VBA Routines and press Del Key to delete them.
- Copy the following VBA Code and paste it into the Code Module of the Form.
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 normal view.
- Click on the Navigation button to move the records forward one by one.
- The names of the employees will be displayed in the same style by moving from right edge of the label to the left.
When you open the Form you will find the Employee Name is moving into place slowly from right to left, character by character, in the header-label.
We will add little fancy work to the Employee Name with a three dimensional backlit effect (icing effect) by copying the Label and placing it over the existing one. See the finished design image given below:
- Open the Employee Form in Design View.
- Select the header label.
- Click on the Copy, Paste Tool Bar buttons to make a copy of the label (or select Copy, Paste Options from View).
- Click on the new Label to select it, if it is not in selected state.
- Display the Property Sheet of the Label (View – ->Properties).
- Change the following Property Values as shown below:
- Name = lbl2
- Fore Color = 128
I have already included the line of code necessary to run this trick. All you have to do is to enable that line in the VBA Code, do the following:
‘Me.lbl2.Caption = txt2
Now you will find the Employee Names appearing in animated characters with 3D effect as shown in the second image above.