Introduction
Last week, we learned a simple label animation method that displayed employee names character by character from the right side of the label. This animation gave the form a lively appearance and made the screen more engaging for the user.
This week, we’ll try a different label animation method using the same set of labels. In the earlier Animation Style, we used two identical labels to create a 3D effect for the employee’s name. We’ll continue with the same design, but this time the labels will be placed horizontally apart in the layout, as shown below:
In the Form_Current Event Procedure, the two labels will be programmed to move in opposite directions. As they gradually approach one another, they will finally align and merge together, forming a 3D-style heading as shown below:
This animation occurs every time an employee record becomes current. The labels restart from their original positions, move gradually in opposite directions, and finally settle to form the 3D-style employee name.
If you have already completed the earlier label animation task, implementing this method will be straightforward. Simply adjust the following property settings for lbl1
and lbl2
, and then copy the VBA routines into the Employee form’s module.
The Label Animation Design.
Open your database where you have tried the earlier example.
Make a copy of the earlier Employee Form. We have tried the Label Animation and named it Employee2.
Open the Employee2 Form in Design View.
Click on the top label in the form’s header and drag it slightly to the right. This will allow you to select each label individually and adjust its properties as needed.
Select the Label with the name lbl1.
Display its Property Sheet (View - -> Properties) and set the following Property Values:
- Name = lbl1
- Width = 2.9924"
- Height = 0.3549"
- Top = 0.1569"
- Left = 2.5194"
- Back Style = Transparent
- Border Style = Transparent
- Font Name = Verdana
- Font Size = 18
- Text Align = Centre
- Font Weight = Bold
- ForeColor = 0
Select the Label with the name lbl2.
Display the Property Sheet and change the following Property Values:
- Name = lbl2
- Width = 2.9924"
- Height = 0.3549"
- Top = 0.125"
- Left = 5.5313"
- Back Style = Transparent
- Border Style = Transparent
- Font Name = Verdana
- Font Size = 18
- Text Align = Centre
- Font Weight = Bold
- ForeColor = 16777215
Display the Code Module of the Form (View -> Code).
Copy and paste the following VBA Code, overwriting the existing Code:
The Form Module VBA Code.
Option Compare Database Option Explicit Private Const twips As Long = 1440 Dim i, j Private Sub Form_Current() Dim txtName As String Me.lbl1.Left = 2.5194 * twips: Me.lbl1.Top = 0.1569 * twips: Me.lbl1.Width = 2.9924 * twips: Me.lbl1.Height = 0.3549 * twips Me.lbl2.Left = 5.5313 * twips: Me.lbl2.Top = 0.125 * twips: Me.lbl2.Width = 2.9924 * twips: Me.lbl2.Height = 0.3549 * twips txtName = Me![first name] & " " & Me![Last name] Me.lbl1.Caption = txtName Me.lbl2.Caption = txtName i = 0 Me.TimerInterval = 5 End Sub Private Sub Form_Timer() Dim m, L1, L2 i = i + 1 m = i Mod 2 Select Case m Case 0 L1 = Me.lbl1.Left L1 = L1 + (0.084 * twips) Me.lbl1.Left = L1 Case 1 L2 = Me.lbl2.Left L2 = L2 - (0.084 * twips) Me.lbl2.Left = L2 End Select DoEvents If i > 35 Then Me.TimerInterval = 0 i = 0 End If End Sub
Save the Employee2 Form.
Open the Employee2 Form in normal view
Click on the Record Navigation control to advance each record forward one by one.
For each record change, you will find the Employee Name Labels move towards each other and assemble into place to form a 3D heading.
No comments:
Post a Comment
Comments subject to moderation before publishing.