Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Digital Clock on Main Switchboard

You may find several pieces of gadgets like Clocks, Wrist Watches and so on around you to check the Date and Time.  How about inserting a Digital Clock into your Project's Main Switchboard Form so that your User can check the Date and Time with a casual glance in the middle of their normal work without interrupting what they are doing?

Besides all that it is a matter of style to put an animated Digital Clock on the Main Switchboard.  It takes only a few lines of VBA Code and a Label Control on the Form.

We can stop the Clock when you open other Forms over the Main-Switchboard and re-start the Clock with current time when the Main-Switchboard become active again.

If you have not started using VBA in your Databases and don't know where to begin then this is the time to learn something interesting and simple.

Let us do it together.

  1. Open one of your existing Databases.
  2. If you have a Control Screen (Main Switchboard) in your database then open it in Design View. You can open any Form in Design View to try this out.
  3. Display the Toolbox (View - ->Toolbox) if it is not visible.
  4. Click on the Label Tool (button face with the letter Aa on it).
  5. Draw a Label where you would like the Digital Clock to appear on the Form.

    I have used a copy of the Main-Switchboard Form from Microsoft Access Sample Database - C:\Program Files\Microsoft Office\Office11\Sample\Northwind.mdb. An image of the Form in Design View, with a Label Control inserted, is given below:

  6. Type at least one character (any character) in the Label control otherwise the label control will get deleted when you click somewhere else.
  7. While the Label Control is still in selected state display its Property Sheet (View - ->Properties).
  8. Change the following Property Values as given below:
    • Name    =   lblClock
    • Width   =  1.5938"
    • Height   =  0.3125"
    • Border Style = Transparent
    • Font Size = 8
    • Font Weight = Bold
    • Text Align   =  Center

    Now, we need two lines of VBA Code to start running our Digital Clock. One line of Code to start running the IntervalTimer of the Form through Form_Load() Event Procedure, immediately after the Switchboard Form is open.

  9. Click on the top left corner of the Form, where the Horizontal and Vertical Rulers meet, to select the Form. Now you will see the Form-level Property Values in the Property Sheet you have displayed earlier. If you have closed the Property Sheet follow Step-7 above to display the Property Sheet of the Form.
  10. Find the On Load Property and click on it to select it.
  11. Select [EventProcedure] from the drop down list box.
  12. Click on the build (. . .) button at the right edge of the Property Sheet to open up the VBA Module with an empty skeleton of VBA Sub-Routine as given below:
    Private Sub Form_Load()
    
    End Sub
  13. Write (or copy) the following line of VBA Code in the middle of the above lines of Code:
        Me.TimerInterval = 1000 

    This line of Code says that the program control should be passed to the Form's Timer Sub-Routine (we will write the code for that next) at every one second interval. So whatever program we will write in the Timer Sub-Routine will be executed sixty times per minute or once every second. We will write a one line Code in the Timer Sub-Routine to take the System Date and Time and update the Caption of the Label we have created at the beginning. So, we will be seeing a continuous time change every second.

  14. Select Timer from the drop-down control at the top of the VBA Module Window.

    The opening and closing lines of the Timer Sub-Routine will be inserted into the VBA Module.  You must write the line given in the middle by giving spaces and other punctuations correctly between double-quotes (date/time format string).

    Private Sub Form_Timer()
        Me.lblClock.Caption = Format(Now(), "dddd dd, mmm-yyyy hh:nn:ss")
    End Sub

    Alternatively you may copy and paste all the three lines of VBA Code anywhere within the Form Module.

  15. Close and Save the Form.
  16. Open the Form in normal View.

Your digital clock will show Current Date and Time and change of time is updated every second.

When you open other Forms or run different programs or macros the Main Switchboard may become inactive and we can turn off the clock temporarily till the Main Switchboard become active again. This will help other programs to run faster without interruption from the digital clock taking time to update the label on the Main Switchboard.

We will write two more lines of Code for the On Deactivate() and On Activate() Event Procedures to turn-off (when the Main Switchboard is inactive) and to turn-on (when the Main Switchboard is active again) respectively.

  1. Open the Form in Design View.
  2. Display the VBA Module of the Form (View - ->Code).
  3. Copy and paste the following VBA Code into an empty area of the Module.
    Private Sub Form_Activate()
        Me.TimerInterval = 1000
    End Sub
    
    Private Sub Form_Deactivate()
        Me.TimerInterval = 0
    End Sub
  4. Save the Form and Close it.
  5. Open it in normal view.
  6. Open some other Form over the Main Switchboard from your database.
  7. Click on the Title Area of the second Form and drag away from the Main Switchboard Form so that you can see the Digital Clock on it.

    You can see that the clock is not getting updated.

  8. Close the second Form.

Now the Main Switchboard Form become active and the Clock will start updating the Date/Time again.

Technorati Tags: ,
Share:

Label Animation Zoom-out Fade

Computer Programming is interesting because when you start doing something it will definitely lead to more than that and give you more ideas to try different things all the time. I have started with the Label Animation methods and thought of presenting one or two tricks but we have gone through five different animation methods by now.

We are going to learn one more trick with the same Form and Labels, which we have used last week. All you need to do is to copy the new VBA Code given below into the Code Module of the Form.

A sample image of the Run of the Program is given below:

In this method the Color of each letter of the Employee name is slowly fading away to distance. The size of each letter of the name is getting reduced at each step and the letters are displayed at a fixed time of interval giving it an animated and three dimensional effect.

If you have not tried out the earlier Label animation methods you may take a look at them by visiting the following pages:

Label Animation Style-1

Label Animation Style-2

Label Animation Variant

Label Animation Zoom-in Style

Label Animation in Colors

Let us try the new method.

  1. Make a copy of the Employees Form we have used last week with twenty small labels with the Name Property set the with the Values lbl01 to lbl20.

    Sample image of the Form is given below for reference:

  2. Open the Employees Form you have copied in Design View.
  3. Display the Code Module of the Form (View - -> Code).
  4. Copy and paste the following VBA Code into the Module, over-writing the existing Code:
    Option Compare Database
    Option Explicit
    
    Dim j, txtName, ctrl As Label, i
    
    
    Private Sub Form_Current()
    Dim t, xRGB As Long, fsize
    
    txtName = UCase(Me![first name] & " " & Me![Last name])
    fsize = 22
    For j = 1 To 20
       Set ctrl = Me("lbl" & Format(j, "00"))
       ctrl.FontSize = fsize
       ctrl.Caption = ""
       fsize = fsize - 1
    Next
       
    xRGB = RGB(10, 10, 10)
    i = xRGB
    For j = 1 To Len(txtName)
       Set ctrl = Me("lbl" & Format(j, "00"))
       xRGB = xRGB + i
       ctrl.ForeColor = xRGB
       ctrl.Caption = Mid(txtName, j, 1)
       
    t = Timer
    Do While Timer < t + 0.1
      DoEvents
    Loop
    
    Next
    
    End Sub
  5. Save the Form with the Code and open it in normal view.
  6. Use the Record Navigation Button and move the record forward or back and watch how the Employee name is displayed on the header of the form.
Share:

Label Animation in Colors

We have learned several label animation methods, through last few Posts dedicated to this topic, but we will try another trick, with the last design that you have created to try out the Zoom-in method.

In this method we will play with colors and each letter of the name is applied with different color generated randomly. Besides that, the name of the employee is plotted in a magical way by displaying odd numbered letters first in odd numbered labels i.e. lbl01, lbl03, lbl05 and even numbered letters displayed in even numbered labels i.e. lbl02, lbl04, lbl06 and so on. The letters will be plotted on the labels in a fixed time interval giving it an animated effect.

After these two step action only the employee name display will be completed on the Header of the Form to view.

You can easily implement this method if you have tried out the earlier label animation method we have seen last week.

  1. Make a Copy of the Employees Form, we have designed last week, and name it as Employees_2 or any other name you prefer.

    Sample design of the Form, with twenty labels placed close together on the Header of the Form, with the Name Property Values set as lbl01 to lbl20, is given below:

  2. Display the Code Module of the Form (View - -> Code), after opening the Form in Design View.
  3. Copy and Paste the following VBA Code into the Form Module overwriting the existing Code.

    Option Compare Database Option Explicit Dim j, txtName, ctrl As Label Private Sub Form_Current() Dim t, m, R, G, B Randomize (Timer) txtName = Me![first name] & " " & Me![Last name] For j = 1 To 20 Set ctrl = Me("lbl" & Format(j, "00")) ctrl.Caption = "" Next For j = 1 To Len(txtName) Step 2 Set ctrl = Me("lbl" & Format(j, "00")) R = Int(Rnd(1) * 64) G = Int(Rnd(1) * 128) B = Int(Rnd(1) * 255) ctrl.ForeColor = RGB(R, G, B) ctrl.Caption = Mid(txtName, j, 1) t = Timer Do While Timer < t + 0.1 DoEvents Loop Next For j = 2 To Len(txtName) Step 2 Set ctrl = Me("lbl" & Format(j, "00")) R = Int(Rnd(1) * 255) G = Int(Rnd(1) * 128) B = Int(Rnd(1) * 64) ctrl.ForeColor = RGB(R, G, B) ctrl.Caption = Mid(txtName, j, 1) t = Timer Do While Timer < t + 0.1 DoEvents Loop Next End Sub

  4. Save the Form with the new VBA Code.
  5. Open the Form in normal view.
  6. Use the record Navigation button to move the record forward or back and watch how the employee name is displayed in the header labels.

The sample screen in Normal View is given below:

Each character of the name will be displayed in different colors and in one tenth of a milli-second's time interval, giving it an animated effect. The color codes are generated randomly.

In this control program we have used two delay loops, instead of using the Form's default Timer Interval Event Procedure.

You can modify the given value 0.1 in the program line Do While Timer < t + 0.1 to increase or decrease the animation speed.

For example: The value 0.5 will slow down the action and 0.05 will run faster.


Share:

Label Animation Zoom-in Style

This week we will learn a different style of Label Animation technique. Those who would like to have a look at the earlier simple label animation methods, the page links are given below to visit those pages:

In all the above methods we have used two labels, which moved towards each other from different directions and placed close together to form the displaying text to look like a 3D heading.

This week we will use a different approach and we need about twenty small labels placed close together horizontally. Each Label will display only one character of the Employee Name and all the employee names are less than twenty characters only.

Sample arrangement of Labels in the design view is given below:

Animation Style image is given below:

The employee name will appear from left to right, character by character in each label, followed by the  letters will Zoom-in and Zoom-out in sequence. The above screen is captured in the middle of that action.

Let us get into the design task of this animation.

  1. If you have not gone through the earlier examples then Import the Employees Table from C:\Program Files\Microsoft Office\Office11\Samples\Northwind.mdb sample database.
  2. Click on the Employees Table and select Form from Insert Menu.
  3. Create a Form as shown above and save it with the name Employees or any suitable name that you prefer.
  4. Open the Form in Design View.
  5. Select the Label Tool from Toolbox and draw a Label control in the header section of the Form.
  6. Change the following property values of the Label as given below:
    • Name = lbl01
    • Width = 0.2528"
    • Height = 0.3549"
    • Top = 0.1563"
    • Left = 1.1146
    • Back Style = Transparent
    • Border Style = Transparent
    • Special Effect = Flat
    • Font Name = Verdana
    • Font Size = 14
    • Font Weight = Bold
    • Fore Color = 7500402

    Now, we must copy this label nineteen times and arrange them as shown on the first image, at the top of this page.

  7. We must also change the Name Property Value of each label sequentially so that we can easily address each label in Programs to change their caption values to display the Employee's name.
  8. Right-Click on the Label and select Copy from the displayed Shortcut Menu.
  9. Select Paste from Edit Menu to create a copy of the Label.
  10. Click and drag the new label and place it to the right of the first label. Don't worry about the misalignment of the labels, we will arrange them easily later.
  11. Repeat the Paste action to create another eighteen labels.
  12. The Labels will appear automatically to the right of earlier labels.

  13. Click on the second Label.
  14. Display its Property Sheet (View- -> Properties).
  15. Change the Name Property value to lbl02.
  16. Repeat this method for other labels also and name them as lbl03, lbl04 and so on up to lbl20.
  17. Click at the left side of the first label (lbl01) and drag the Mouse over all the twenty labels to select them all together.
  18. Select Format - -> Align - -> Top to align all Labels horizontally.
  19. Select Format - -> Align - -> Left to bring all the Labels close together.

    Now, that we have arranged the labels and their Name Property Values set to lbl01 to lbl20 all that is left to do is to copy the following Programs into the Form's Code Module.

  20. Select Code from View Menu.
  21. Copy and Paste the following VBA Code into the Module (overwriting the existing VBA Code, if any).
    Option Compare Database
    Option Explicit
    
    Private Const twips As Long = 1440
    Dim i, j, txtName, ctrl As Label
    
    Private Sub Form_Current()
    
    txtName = UCase(Me![first name] & " " & Me![Last name])
    i = 0
    Me.TimerInterval = 50
    
    End Sub
    
    Private Sub Form_Timer()
    Dim m, L1, L2
    i = i + 1
    If i > Len(txtName) Then
       For j = Len(txtName) + 1 To 20
        Set ctrl = Me("lbl" & Format(j, "00"))
        ctrl.Caption = ""
        Next
       Me.TimerInterval = 0
       i = 0
       animate
    Else
       Set ctrl = Me("lbl" & Format(i, "00"))
       ctrl.Caption = Mid(txtName, i, 1)
       ctrl.ForeColor = &H727272
    End If
    DoEvents
    
    End Sub
    
    Public Function animate()
    Dim k As Integer, t
    For k = 1 To Len(txtName)
      Set ctrl = Me("lbl" & Format(k, "00"))
      ctrl.ForeColor = 0
      ctrl.FontSize = 24
      DoEvents
      If k = 10 Then Exit For
      t = Timer
      Do While Timer < t + 0.09
        DoEvents
      Loop
      ctrl.FontSize = 14
    
    Next
    
    End Function
  22. Save the Form with the Code.
  23. Open it in normal view.
  24. Use the Record Navigation Buttons to advance the record one by one forward/back to display the employee name animated.

Hope you like this method better and implement it in your Projects.

Share:

Label Animation Variant

I have several Label Animations Styles in store for you and we have already seen two of them through last two Articles:

  1. Label Animation Style-1
  2. Label Animation Style-2

Here, we will examine two variants of the last animation method we have tried last week. If you have gone through the procedures in creating the sample labels and programs then we can try the same animation method with slightly different settings of the labels.

The change is required only on the position of the second label lbl2. The arrangement of labels of last animation method we have tried last week is given below:

Both labels are placed apart and moved towards each other before they are positioned on the final destination to form the 3D Heading Style.

If you think it is better if the distance of both labels are reduced and place them little bit closer so that the animation style have a better appeal then here it is for you to try it. 

The modified version of the above design is given below:

You can implement this variant of the earlier animation style by changing the Properties of the lbl2 label as given below. 

  1. Make a copy of the Employees Form with the earlier animation method and change the Form name something like Employee2_1 or any other name you prefer.
  2. Open the Employee2_1 in Design View.
  3. Click on lbl2 (the label with White coloured label and display its Property Sheet (View - -> Properties).
  4. Change the Property Values as shown below. The only change that you need to make is the left Property value only. But, the full Property Values are reproduced here with change in Left Property:
    • Width = 2.9924
    • Height = 0.3549
    • Top = 0.125
    • Left = 3.6354
    • Back Style = Transparent
    • Border Style = Transparent
    • Font Name = Verdana
    • Font Size = 18
    • Text Align = Center
    • Font Weight = Bold
    • Fore Color = #FFFFFF

    Once you make the Left Property Value change the label will move into place as shown in the second image above.

  5. Display the Code Module of the Form (View - -> Code) while the Employee2_1 Form is still in design view.
  6. Copy and paste the following modified Code into the Form Module over-writing the existing VBA Code.
    Option Compare Database
    Option Explicit
    'Global declarations
    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 = 3.6354 * twips
    Me.lbl2.Top = 0.125 * twips
    Me.lbl2.Width = 2.9924 * twips
    Me.lbl2.Height = 0.3549 * twips
    
    txtName = UCase(Me![first name] & " " & Me![Last name])
    Me.lbl1.Caption = txtName
    Me.lbl2.Caption = txtName
    i = 0
    Me.TimerInterval = 25
    
    End Sub
    
    Private Sub Form_Timer()
    Dim m, L1, L2
    i = i + 1
    m = i Mod 2
    Select Case m
        Case 1
            L1 = Me.lbl1.Left
            L1 = L1 + (0.084 * twips)
            Me.lbl1.Left = L1
        Case 0
            L2 = Me.lbl2.Left
            L2 = L2 - (0.084 * twips)
            Me.lbl2.Left = L2
    End Select
    DoEvents
    If i > 12 Then
       Me.TimerInterval = 0
       i = 0
    End If
            
    End Sub
  7. Save the Form and open it in Normal View.
  8. Move the Employee Records forward using the record navigation buttons and watch the refined animation of employee names.

I hope you like the over all impact of the change in the earlier animation method.

We will look into another variant of the same animation method with the following design change:

In this method we place lbl2 named label below lbl1 and slowly move them towards each other and place them in such a way that they form into a 3D header.

  1. Make a Copy of the Employee2_1 Form and save it with the name Employee2_2.
  2. Open the Form in Design View.
  3. Click on the label with the White coloured text (with the Name Property Value lbl2) to select it.
  4. Display the Property Sheet (View- -> Properties) and change the following Property Values as shown below:
    • Width = 2.9924
    • Height = 0.3549
    • Top = 0.5313
    • Left = 2.5729
    • Back Style = Transparent
    • Border Style = Transparent
    • Font Name = Verdana
    • Font Size = 18
    • Text Align = Center
    • Font Weight = Bold
    • Fore Color = #FFFFFF
  5. Display the Code Module of the Form (View- ->Code).
  6. Copy and Paste the following Code into the Form VBA Module over-writing the existing 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.5521 * twips
    Me.lbl1.Top = 0.1569 * twips
    Me.lbl1.Width = 2.9924 * twips
    Me.lbl1.Height = 0.3549 * twips
    
    Me.lbl2.Left = 2.5729 * twips
    Me.lbl2.Top = 0.5313 * 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 = 50
    
    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.Top
            L1 = L1 + (0.084 * twips)
            Me.lbl1.Top = L1
        Case 1
            L2 = Me.lbl2.Top
            L2 = L2 - (0.084 * twips)
            Me.lbl2.Top = L2
    End Select
    DoEvents
    If i > 4 Then
       Me.TimerInterval = 0
       i = 0
    End If
            
    End Sub
    
    
  7. Save the Form and open it in normal View.
  8. Try moving the Employee records forward and watch the new method of the same style of animation.

Next week we will learn a different and interesting style of label animation method.

Share:

Translate



PageRank
Your email address:

Delivered by FeedBurner

Search

Infolinks Text Ads


Blogs Directory

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Labels

Forms How Tos Functions MS-Access Security Reports msaccess forms Animations msaccess animation Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Queries External Links msaccess reports msaccess tips Menus and Toolbars Accesstips MsaccessLinks Process Controls Art Work Downloads msaccess How Tos Graph Charts msaccessQuery List Boxes Command Buttons Emails and Alerts Query Combo Boxes Custom Wizards DOS Commands ms-access functions msaccess functions msaccess graphs msaccess reporttricks msaccessprocess security advanced Access Security Array Custom Functions Data Macros Menus Property Report Top Values VBA msaccess email msaccess menus progressmeter Access2007 Auto-Number Command Button Copy Form Join Microsoft Numbering System Records Security Split SubForm Table Utility Variables Workgroup database msaccess wizards Access2003 Accounting Year Action Animation Attachment Binary Numbers Bookmarks Budgeting Calculation ChDir Color Palette Conditional Formatting Controls Data Filtering Data Type Defining Pages Diagram Disk Dynamic Lookup Error Handler Excel Export Expression External Field Type Fields Filter Form Instances Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Methods Monitoring Object Reference Objects Octal Numbers Operating System Paste Primary-Key Product Rank Reading Recordset Rich Text Sequence SetFocus Summary Tab-Page Tables Time Difference Union Query User Users Water-Mark Word automatically commands function hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar tutorial updating upload vba code

Featured Post

Function Parameter Array Passing

Last week we have explored the usage of ByVal (By Value) and ByRef (By Reference),  in the Function Parameter, to pass the value from  a Va...

Labels

Blog Archive

Recent Posts