Microsoft Access VBA Tutorials for self-paced learning, Class Modules, SQL Techniques, and AI Integration Guides.

Label Animation Zoom-out Fade

Label Animation Zoom-out Fade. 

Computer programming is fascinating because once you begin experimenting, it often sparks new ideas and leads you to try even more. I originally planned to demonstrate just one or two label animation techniques, but we’ve already explored five different animation methods.

Now, we’ll learn one more trick using the same form and labels we worked with last week. All you need to do is copy the new VBA code into the Form's code module.

The sample image below shows the program in action:

In this method, the color of each letter in the employee’s name gradually fades as if receding into the distance. At the same time, the size of each letter decreases progressively. The letters are displayed at fixed time intervals, creating an animated effect with the sense of three-dimensional depth.

Links to earlier Animation Styles.

If you have not tried out the earlier Label animation methods, you may explore them by visiting the following pages:

  1. Label Animation Style-1
  2. Label Animation Style-2
  3. Label Animation Variant
  4. Label Animation Zoom-in Style
  5. Label Animation in Colors

Let us try the new method.

The Design Task.

  1. Make a copy of the Employees form we used last week. On this form, create twenty small labels, and set their Name property to the values lbl01 through lbl20.

    A sample image of the Form is given below for reference:

  2. Open the Employees Form you have copied in Design View.

  3. Display the Form's Code Module (View -> Code).

  4. Copy and paste the following VBA Code into the Module, overwriting the existing Code:

    The Form Module 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 the normal view.

  6. Use the Record Navigation buttons to move forward or backward through the records, and observe how the employee name is displayed dynamically in the form’s header.

  1. Textbox and Label Inner Margins
  2. Animating Label on Search Success
  3. Label Animation Style-1
  4. Label Animation Style-2
  5. Label Animation Variant
  6. Label Animation Zoom-in Style
  7. Label Animation in Colors
  8. Label Animation Zoom-out Fade
Share:

Label Animation in Colors

Label Animation in Colors.

We have explored several label animation methods in the previous posts, and now we will try another trick using the last design you created: the Zoom-in method.

In this method, we add a splash of color—each letter of the employee’s name is assigned a randomly generated color. The letters are plotted in a “magical” sequence: odd-numbered letters appear first on odd-numbered labels (lbl01, lbl03, lbl05, etc.), followed by even-numbered letters on even-numbered labels (lbl02, lbl04, lbl06, etc.). The letters are displayed at fixed time intervals, creating a smooth animated effect.

After these two steps, the employee’s name is fully displayed in the form header, producing an eye-catching Zoom-in animation.

If you have tried the earlier label animation methods from last week, implementing this technique will be straightforward and easy to follow.

The Design Task.

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

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

  2. Display the Form's Code Module (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.

    The Form Module 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.

    The Demo Run.

  5. Open the Form in the 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 name character is displayed in a different color at a 0.1-second interval, creating a smooth animated effect. The color codes are generated randomly.

    In this program, we use two delay loops instead of the form’s default Timer Interval event procedure.

    You can adjust the animation speed by modifying the value in the line:

    Do While Timer < t + 0.1

    For example:

    • 0.5 will slow down the animation.

    • 0.05 will make it run faster.

    This gives you full control over the speed of the Zoom-in effect.

  1. Textbox and Label Inner Margins
  2. Animating Label on Search Success
  3. Label Animation Style-1
  4. Label Animation Style-2
  5. Label Animation Variant
  6. Label Animation Zoom-in Style
  7. Label Animation in Colors
  8. Label Animation Zoom-out Fade
Share:

Label Animation Zoom-in Style

Label Animation Zoom-in Style.

This week, we will explore a different style of label animation technique. If you would like to revisit the earlier, simpler label animation methods, the links to those pages are provided below.

In all the earlier methods, we used two labels moving toward each other from opposite directions, coming together to form text that appeared like a 3D heading.

This week, we will take a different approach. For this method, you will need about twenty small labels placed close together in a horizontal line. Each label will display a single character of the employee’s name. Since all employee names are fewer than twenty characters, this arrangement will be sufficient.

A sample layout of the labels in Design View is shown below:


Animation Style image.

The employee’s name will appear from left to right, one character at a time, across the labels. After the full name is displayed, the letters will zoom in and zoom out sequentially, creating a dynamic animated effect.

The screenshot above was captured live of this action.

The Design Task.

Let us complete the design task of this animation.

  1. If you have not explored the earlier examples, then import the Employees Table from the Northwind sample database.

  2. Click the Employees Table and select Form from the Insert Menu.

  3. Create a Form as shown above and save it named Employees.

  4. Open the Form in Design View.

  5. Select the Label Tool from the Toolbox and draw a Label control in the Form's header section.

  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
    • ForeColor = 7500402

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

  7. Change the Name Property Value of each label sequentially, lbl01, lbl02, lbl03, and so on, 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 the Edit Menu to create a copy of the Label.

  10. Click and drag the new label to 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.

    The Labels will appear automatically to the right of earlier labels.

  12. Click on the second Label.

  13. Display its Property Sheet (View -> Properties).

  14. Change the Name Property value to lbl02.

  15. Repeat this method for other labels, naming them sequentially as lbl03, lbl04, and so on up to lbl20.

  16. Click outside the first label (lbl01), hold the left mouse button, and drag the Mouse over the labels to select them all together.

  17. Select Format -> Align -> Top to align all Labels horizontally.

  18. Select Format -> Align -> Left to bring all the Labels close together.

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

  19. Select Code from the View Menu.

  20. Copy and paste the following VBA Code into the Module (overwriting the existing VBA Code, if any).

    The Form Module Code.

    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

    The Trial Run.

  21. Save the Form with the Code.

  22. Open it in the normal view.

  23. Use the Record Navigation Buttons to move the record forward/back and display the employee name in animated form.

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

  1. Textbox and Label Inner Margins
  2. Animating Label on Search Success
  3. Label Animation Style-1
  4. Label Animation Style-2
  5. Label Animation Variant
  6. Label Animation Zoom-in Style
  7. Label Animation in Colors
  8. Label Animation Zoom-out Fade
Share:

Label Animation Variant

Label Animation Variant.

I have several label animation styles lined up to share with you, and we have already explored two of them in the last two articles:

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

In this lesson, we will explore two variations of the animation method we practiced last week. If you have already followed the earlier tutorials creating the sample labels and writing the program, you can reuse the same setup with only a few small adjustments.

The only change needed is in the position of the second label (lbl2). The arrangement of labels from the previous animation method is shown below:

In this method, both labels are initially placed apart and then move toward each other until they meet at the final position, forming the 3D heading style.

If you prefer a variation with a stronger visual appeal, you can reduce the distance between the two labels and place them slightly closer together. This adjustment gives the animation a smoother and more polished effect.

The modified version of the design is shown below:

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

The Design Change.

  1. Make a copy of the Employees Form with the earlier animation method and change the Form name to something like Employee2_1 or any other name you prefer.

  2. Open Employee2_1 in Design View.

  3. Click on lbl2 (the White-colored label) and display its Property Sheet (View -> Properties).

  4. Change the Property Values as shown below. The only change you need to make is the left Property value. But the full Property Values are given below.

    • 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
    • ForeColor = #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 the design view.

  6. Copy and paste the following modified Code into the Form Module, overwriting the existing VBA Code.

    The Form Module 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 overall impact of the change in the earlier animation method.

The Design Changes.

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

  1. In this method, the label  lbl2 is placed below lbl1. Both labels are then gradually moved toward each other until they overlap, creating a 3D-style header.

  2. Make a Copy of the Employee2_1 Form and save it named Employee2_2.

  3. Open the Form in Design View.

  4. Click the label with white text to select it.

  5. 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
    • ForeColor = #FFFFFF
  6. Display the Code Module of the Form (View ->Code).

  7. Copy and paste the following Code into the Form VBA Module, overwriting the existing Code.

    The Form Module 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
    
    
  8. Save the Form and open it in Normal View.

  9. Move the employee records forward using the Record Navigation buttons and observe how the new animation method is applied in the same 3D style.

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

  1. Textbox and Label Inner Margins
  2. Animating Label on Search Success
  3. Label Animation Style-1
  4. Label Animation Style-2
  5. Label Animation Variant
  6. Label Animation Zoom-in Style
  7. Label Animation in Colors
  8. Label Animation Zoom-out Fade
Share:

Label Animation Style-2

Label Animation Style-2.

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 start 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.

  1. Open your database where you have tried the earlier example.

  2. Make a copy of the earlier Employee Form. We have tried the Label Animation and named it Employee2.

  3. Open the Employee2 Form in Design View.

  4. 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.

  5. Select the Label named lbl1.

  6. 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
  7. Select the Label named lbl2.

  8. 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
  9. Display the Form Module (View -> Code).

  10. 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
  11. Save the Employee2 Form.

  12. Open the Employee2 Form in normal view

  13. 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.

  1. Textbox and Label Inner Margins
  2. Animating Label on Search Success
  3. Label Animation Style-1
  4. Label Animation Style-2
  5. Label Animation Variant
  6. Label Animation Zoom-in Style
  7. Label Animation in Colors
  8. Label Animation Zoom-out Fade
Share:

Label Animation Style-1

Label Animation Style-1.

A form with lively elements—such as animated command buttons, GIFs, or moving text—makes working with MS Access applications more interesting for users. 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: 

Today, we will learn a simple label animation technique using an example from the Employees form in the Northwind.mdb sample database.

  1. 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—first name and last name 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: the employee name appears character by character, moving slowly from the right edge of the label to the left, then settling into place.

  2. Open the Employees Form in Design View.

  3. Delete the existing TextBox that displays the Employee's Name.

  4. Create a Label on the Header Section of the Form.

  5. 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
  6. Display the Code Module of the Form (View ->Code).

  7. Press Ctrl+A to select and highlight the existing VBA Routines and press the Del key to delete them.

  8. 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
  9. Save and Close the Employees Form.

  10. Open the Employees Form in the normal view.

  11. 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.

  12. Click the forward Navigation records button to move the records one by one.

  13. The employee names will be displayed in the same style by moving from the right edge of the label to the left.

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:

  1. Open the Employee Form in Design View.

  2. Select the header label.

  3. Create a copy of the header label.

  4. Display the Label's Property Sheet (View ->Properties).

  5. Change the following Property Values as shown below:

    • Name = lbl2
    • ForeColor = 128
  6. Place the copied label above the first label, slightly down and to the left from the top and left edge, respectively. The sample image design view is given below:

  7. 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 and do the following:

  8. While the Form is still in design view, display the VBA Module (View ->Code)

  9. You will find the following line of code in the Sub Form_Timer() Event Procedure in a different color (most probably in green color):

  10. 'Me.lbl2.Caption = txt2

  11. Find the ' (single quote) character at the beginning of this line and delete it.

  12. Save and Close the Form.

  13. Open the Form in the Normal View.

    Now you will find the Employee Names appearing in animated characters and in 3D style, as shown in the second image above.

  1. Textbox and Label Inner Margins
  2. Animating Label on Search Success
  3. Label Animation Style-1
  4. Label Animation Style-2
  5. Label Animation Variant
  6. Label Animation Zoom-in Style
  7. Label Animation in Colors
  8. Label Animation Zoom-out Fade
Share:

Group Account Permissions with VBA

Group Account Permissions with VBA.

    We have learned how to remove all permissions from every object for the Users Group Account. Since all users belong to this default group, they inherit any permissions assigned to it, in addition to those from other group accounts they are members of.

    If you haven’t reviewed the earlier articles on Microsoft Access Security using VBA, it’s recommended to go through the following links before continuing.

    Nature of Permission Assignment.

    Last week, we discussed how to remove all permissions from a specific group account. This week, we’ll learn how to assign different sets of permissions for each type of object—Tables, Queries, Forms, and others—to a particular group account. Once this setup is complete, all users belonging to that group will have restricted access to the designated objects.

    For Tables and Queries, Users cannot make design changes, but they can view the Table Structure or Query Design. Users can add, edit, or Delete Records in Tables.

    Users can open Run Forms and Reports, but cannot view or make Design Changes.

    Macros can be run but cannot be viewed or changed in design.

    Automating Object-Level Permission Settings.

    The VBA Routine given below runs for an external Database and sets permissions for the given User-Group Account in the active Workgroup Information File.

    1. Remember, usernames, passwords, and user-group accounts are stored in the Workgroup Information File (.mdw), while permission settings are saved within the individual databases. In that sense, Microsoft Access security works like a two-part combination lock-key system.

    2. Copy and paste the following VBA Code into a Standard Module of your Database.

      Public Function SetPermission2Grp(ByVal DatabaseName As String, ByVal GroupName As String) As Boolean
      '-------------------------------------------------------------------------
      'Author : a.p.r. pillai
      'Date   : March-2010
      'Purpose: To Assign Security Permissions to Objects
      '       : for a particular Security Group Account
      '       : in an external Database.
      'Note   : The Security Group Account must be present
      '       : in the active Workgroup Information File
      '       :'Remarks: All Rights Reserved by www.msaccesstips.com
      '-------------------------------------------------------------------------
      Dim wsp As Workspace, db As Database, ctr As Container, doc As Document
      Dim ctrName As String, docName As String
      Dim L4 As String
      Const OBJSFULL = &HD01FE
      Const dbOpenRun = 2
      Const FrmRptOpenRun = 256
      Const MacOpenRun = 8
      Const TblQryExcludingModifyAdmin = 244 'All permissions Exluding Modify & Administr
      'Assign Permissions to Group Account
      On Error GoTo SetPermission2Grp_Err
      Set wsp = DBEngine.Workspaces(0)
      Set db = wsp.OpenDatabase(DatabaseName)
      wsp.Groups.Refresh
      For Each ctr In db.Containers
      ctrName = ctr.Name
      ctr.UserName = GroupName
      Select Case ctrName
      Case "Databases"
      For Each doc In ctr.Documents
               docName = doc.Name
               doc.UserName = GroupName
               Select Case docName
                 Case "MSysDb"
                   'Set Open/Run Permissions to Database Object
                    doc.Permissions = doc.Permissions Or dbOpenRun
               End Select
            Next doc
      
         Case "Forms"
          'Set Open/Run Permissions to Forms Container
            ctr.Permissions = ctr.Permissions Or FrmRptOpenRun
            ctr.Inherit = True
            For Each doc In ctr.Documents
               docName = doc.Name
               doc.UserName = GroupName
               'Set Open/Run Permissions to Each Form
              doc.Permissions = doc.Permissions Or FrmRptOpenRun
            Next doc
      
         Case "Reports"
          'Set Open/Run Permissions to Reports Container
            ctr.Permissions = ctr.Permissions Or FrmRptOpenRun
            ctr.Inherit = True
            For Each doc In ctr.Documents
               docName = doc.Name
               doc.UserName = GroupName
               'Set Open/Run Permissions to Each Report
               doc.Permissions = doc.Permissions Or FrmRptOpenRun
            Next doc
      
         Case "Scripts"
           'Set Open/Run Permissions to Macros Container
            ctr.Permissions = ctr.Permissions Or MacOpenRun
            ctr.Inherit = True
            For Each doc In ctr.Documents
               docName = doc.Name
              doc.UserName = GroupName
               'Set Open/Run Permissions to Each Macro
               doc.Permissions = doc.Permissions Or MacOpenRun
            Next doc
      
         Case "Tables"
            '1. Assigns Full Permissions to Tables & Queries
            ctr.Permissions = ctr.Permissions Or OBJSFULL
            ctr.Inherit = True
            For Each doc In ctr.Documents
              docName = doc.Name
              doc.UserName = GroupName
               L4 = Left$(docName, 4)
             'Exclude System Objects
              If L4 = "MSys" Or L4 = "~sq_" Then
                GoTo nextloop
              End If
              '2. Remove Modify and Administrator permissions
              doc.Permissions = doc.Permissions Or TblQryExcludingModifyAdmin
      nextloop:
            Next doc
        End Select
      Next
       ctrSetPermission2Grp = false
      
      SetPermission2Grp_Exit:
      Set db = Nothing
      Set wsp = Nothing
      Exit Function
      
      SetPermission2Grp_Err:
      MsgBox Err & ": " & Err.Description, , "SetPermission2Grp"
      SetPermission2Grp = True
      Resume SetPermission2Grp_Exit
      End Function

    3. To test the Program, create a copy of any Database and find a Group Account that is not assigned permissions for the target database.

    4. Press Alt+F11 to open the VBA Editing Window if you have already closed it.

    5. Press Ctrl+G to open the Debug Window.

    6. Type the following Statement in the Debug Window and press the Enter Key to run the Code and assign permissions to the selected Group Account in the Test Database:

      SetPermission2Grp "C:\My Documents\TestData.mdb", "FAGRP"
    7. Replace the Pathname of the Database and the Security Group Account Name with your own.

    8. After running the Code, open the Test Database and check the Permission Settings of the Group Account you have specified as the parameter.

    Note: You may run the Program from a Command Button Click after assigning the Database path name and Security Group Account Name in text boxes.

    Earlier Post Link References:

Share:

Users Group and Permissions

Users Group and Permissions.

Making a Database Truly Secure

When you create a new Workgroup Information File (.mdw) As part of implementing Microsoft Access security, there are two essential steps you must complete immediately:

  1. Create a new Administrator User ID (for example, myAdmin, or any name you prefer) and add this user as a member of the Admins Group.

  2. Remove the default Admin user account from the Admins Group.

    If you skip this step, your database remains insecure—anyone can open and use it if Microsoft Office is reinstalled.

From this point forward, you must use your new user ID (myAdmin) to log in as the database administrator for any databases associated with this new Workgroup Information File.

Additionally, any databases you create while logged in as myAdmin will have that account automatically designated as the owner of the database and all its objects.

Remember:

  • The database owner has full authority over all objects, including administrative rights to assign permissions and transfer ownership.

  • When ownership of a specific object is transferred to another user, that user gains complete control over it—they can run, modify, or delete the object.

Next, let’s look at how to assign object-level access rights to a user group.

You must set object-level access rights for user groups before deploying your project for public use. This process is performed manually through the menu path:
Tools → Security → User and Group Permissions.

This procedure also includes an essential first step, similar to the two priority steps mentioned earlier for the Workgroup Information File. The step is to remove all permissions for all objects assigned to the Users Group Account.

Without completing this step, any permission settings you later assign to objects—such as Forms, Reports, or Tables—will have no effect, and users will retain full access, including the ability to make design changes or modify the objects freely.

This process can be time-consuming when done manually, as it requires reviewing and clearing permissions for every object group. Since this step is necessary for all new projects, I decided to automate it with a VBA-based procedure, which I’m sharing here for you to try.

Automated Removal of Object-level Permissions.

  1. Copy and paste the following Program into a Standard Module and save it.

    Public Function DefaultUsersGrp(ByVal DatabasePathName As String) As Boolean
    '----------------------------------------------------------------------------
    'Author : a.p.r. pillai
    'Date     : March-2010
    'Purpose: Remove All Permissions from Users Group Security Account
    'All Rights Reserved by www.msaccesstips.com
    '----------------------------------------------------------------------------
    Dim wsp As Workspace, db As Database, ctr As Container
    Dim GroupName As String, doc As Document
    Dim L4 As String
    
    Const DB_FULLNO = &H60000
    Const OBJS_FULLNO = &H2FE01
    
    'Remove All Permissions on Containers & documents
    'for USERS Group
    
    On Error GoTo DefaultUsersGrp_Err
    
    Set wsp = DBEngine.Workspaces(0)
    Set db = wsp.OpenDatabase(DatabasePathName)
    
    wsp.Groups.Refresh
    GroupName = "Users"
    
    Set ctr = db.Containers("Databases")
    Set doc = ctr.Documents("MSysDb")
    doc.UserName = GroupNamedoc.Permissions = DB_FULLNO
    
    Set ctr = db.Containers("Tables")
    GoSub SetPermission
    
    Set ctr = db.Containers("Forms")
    GoSub SetPermission
    
    Set ctr = db.Containers("Reports")
    GoSub SetPermission
    
    Set ctr = db.Containers("Scripts")
    GoSub SetPermission
    
    Set ctr = db.Containers("Modules")
    GoSub SetPermission
    DefaultUsers_Grp = False
    
    DefaultUsers_Grp_Exit:
       Set db = Nothing
       Set wsp = Nothing
    Exit Function
    
    SetPermission:
    For Each doc In ctr.Documents
        doc.UserName = GroupName
        If ctr.Name = "Tables" Then
            L4 = Left$(docName, 4)
            If L4 = "MSys" Or L4 = "~sq_" Then
              GoTo nextloopxxx
            End If
        End If
        doc.Permissions = OBJS_FULLNO
    nextloopxxx:
    NextReturn
    
    DefaultUsersGrp_Err:
    MsgBox Err & ": " & Err.Description
    DefaultUsersGrp = True
    Resume DefaultUsersGrp_Exit
    End Function

    Points to Note.

  2. Remember, this program is designed to be run on an external database—specifically, the one from which you want to remove all permissions for all objects assigned to the Users Group Account.

  3. Before running the program, open the target database and review the current permission settings of all objects for the Users Group Account. It’s strongly recommended that you test the program on a copy of the original database first, to ensure that your data and structure remain safe.

  4. Open the Database with the above Code if you have closed it.

  5. Press Alt+F11 to display the VBA Editing Window and press Ctrl+G to display the Debug Window.

  6. Type the following and press the Enter Key:

    Default UsersGrp "C:\My Documents\myTest.mdb"

  7. Replace the database Pathname in quotes with your own database name.

    You may run the Program from a Command Button Click Event Procedure from a Form.

  8. Open your test database and review the current permission settings for the Users Group Account. You’ll notice that all the check marks from the permission options have now disappeared, confirming that the permissions have been successfully removed.

Earlier Post Link References:

Share:

Create Security Group Account with VBA

Create Security Group Account with VBA.

Last week, we learned how to create a Microsoft Access Security User Account (SMITHJOHN) with VBA and how to join him as a member of the default Group Account Users. The Users and Admins Group Accounts are already present in the default Workgroup Information File (Sytem.mdw ) or in the new Workgroup Information File that you create separately.

If Users need to be organized into categories such as Managers, Supervisors, Data Entry Operators, Editors, and others, access rights can be defined at the group level instead of for individual Users. Any number of Users can be assigned to a group. Once the access rights for a group are defined, every User assigned to that group automatically inherits the privileges granted to it.

One User can be joined to more than one Group as well. A sample image of the User and Group Accounts control image is shown below, and we will examine how the User SMITHJOHN's Security credentials appear in the Control.

In the User Name control, SMITHJOHN is selected. Under the Member label, the Users Group Account is displayed, indicating that this user currently belongs only to that group. The Users Group Account also appears in the Available Group List. Unlike the Users Group Account, which is the default group, the other Group Accounts listed under the Available Group List have been created manually to organize different categories of Users.

To make the user SMITHJOHN a member of the VEHGRP Group Account, select VEHGRP from the Available Groups list and click the Add >> Command Button. This action copies the group name to the Member list. Once added, the selected user automatically inherits all the Access Privileges assigned to the VEHGRP Group Account.

At the end of last week's main program, CreateUser, the following code segment is doing exactly what we did manually in the above paragraph:

. . .
   With wsp
     Set tempGrp = .Users(UsrName).CreateGroup("Users")
         .Users(UsrName).Groups.Append tempGrp
         .Users.Refresh
   End With

Creating the Group Account.

Create the Group Account VEHGRP by going through the same procedure as creating a new User Account from the Groups Tab on the Control above. So, the VEHGRP Account was created at some point in time earlier.

Here, we will learn:

  1. How to create a Microsoft Access Security Group Account MANAGER with VBA.
  2. How to join the User SMITHJOHN to the MANAGER Group Account with VBA.

NB: User and Group Accounts are not case-sensitive. Here they are given in uppercase for legibility only.

The following Program creates the MANAGER Group Account in the Available Groups List:

Public Function CreateUserGrp()
'---------------------------------------------------------------------
'Creating a Security Group Account
'Author : a.p.r. pillai
'Date   : March-2010
'All Rights Reserved by www.msaccesstips.com
'---------------------------------------------------------------------
Dim newGrp As Group, wsp As Workspace
Dim tempGrp As Group
Dim grpName As String, grpID As String

On Error Resume Next

Set wsp = DBEngine.Workspaces(0)

    grpName = "MANAGER"
    grpID = "MGR13579"

With wsp
    Set newGrp = .CreateGroup(grpName, grpID)
               .Groups.Append newGrp

    If Err = 3390 Then
      MsgBox "Group Name : " & grpName & vbCr & vbCr & "Group PID     : " & grpID & vbCr & vbCr & "Account Name already Exists..! "
      Err.Clear
    End If

      .Groups.Refresh
End With

End Function
  1. Copy and paste the above program into a Standard Module.
  2. Click somewhere in the middle of the Code and press the F5 Key to run the Code and create the MANAGER Group Account.
  3. You may select Tools -> Security -> User and Group Accounts (from the Database Window).
  4. Select SMITHJOHN in the User Name List.
  5. Check for the name MANAGER in the Available Groups List, and you will find it there.

Adding the User Account to a Group.

But the User SMITHJOHN is not yet added to the MANAGER Group Account, and this is where we need to add the code segment given at the top of this page to the main program.

The revised VBA Code is given below to create the MANAGER Group Account and to add the User SMITHJOHN to this Group Account.

Public Function CreateUserGrp()
'---------------------------------------------------------------------
'Creating a Security Group Account
'Author : a.p.r. pillai
'Date   : March-2010
'All Rights Reserved by www.msaccesstips.com
'---------------------------------------------------------------------
Dim newGrp As Group, wsp As Workspace
Dim tempGrp As Group
Dim grpName As String, grpID As String

On Error Resume Next

Set wsp = DBEngine.Workspaces(0)

    grpName = "MANAGER"
    grpID = "MGR13579"

With wsp
    Set newGrp = .CreateGroup(grpName, grpID)
               .Groups.Append newGrp
    If Err = 3390 Then
      MsgBox "Group Name : " & grpName & vbCr & vbCr & "Group PID     : " & grpID & vbCr & vbCr & "Account Name already Exists..! "
      Err.Clear
    End If

      .Groups.Refresh
End With

'Add the User SMITHJOHN to the MANAGER Group Account
usrName = "SMITHJOHN"

   With wsp
     Set tempGrp = .Users(usrName).CreateGroup(grpName)
         .Users(usrName).Groups.Append tempGrp
         .Users.Refresh
   End With
End Function

Running the Code a Second Time.

If you run the revised Code again, it will show an Error Message saying that the MANAGER Group Account already exists, because you have already run this code once. But the remaining part of the code will run.

If you open the User and Group Accounts control now and select SMITHJOHN in the User Name Control, you can see that the MANAGER group name is now appearing under the Member List, indicating that the User is a member of the MANAGER Group Account.

See the sample image given below.

Share:

Creating User-Account with VBA

Creating a User Account with VBA.

To create a Microsoft Access user account in the Workgroup Information File '.mdw', navigate to:
Tools → Security → User and Group Accounts → User Name tab.
There, provide a unique User Name and a Personal ID to create a new user account.

We discussed this procedure earlier in the Security Main Menu. The User IDs, Personal IDs, Workgroups, and Passwords are stored in the Workgroup Information File, a database with the '.mdw' extension. The default file used by Microsoft Access is SYSTEM.MDW.

Access privileges for database objects are stored within the database itself. Together, these two components form the combination lock of Access security:

  • The User ID and Personal ID stored in the Workgroup Information File act as the key, and

  • The object-level access rights stored within the database serve as the lock.

A user gains access to specific objects only when the correct User ID, Password, and Personal ID are provided.

The Personal ID is a critical part of each user’s profile—it is required if you ever need to recreate a Workgroup Information File after the original one becomes corrupted or lost.

Only Administrators (members of the Admins Group with administrative privileges) have the authority to create and manage User and Group IDs.

Creating a User Account Manually.

First, let’s create a test user account manually. Follow the procedure given below to create a user account step by step.

User Name: JOHNSMITH (maximum 20 characters)

  • Personal ID: JS123456 (4 to 20 Alphanumeric characters)

Visit the link: Create MS-Access User Account for more details.

  1. Select Tools -> Security -> User and Group Accounts

  2. Click New in the Users Tab.

  3. Type JOHNSMITH in the Name control.

  4. Type JS123456 in the Personal ID control.

  5. Click OK to complete the procedure.

The Users Group.

By default, all User Accounts are added to the Users Group Members. If a user needs to belong to additional user groups, you must select the desired group name from the Available Groups list and add it to the Member Of list using the control on the right-hand side.

Now, let’s learn how to create a user account using VBA—excluding, for now, the step that assigns the user to a specific group. We’ll explore how to link users to groups later, after we cover the topic: how to create a group account with VBA.

Create a User Account with VBA.

The following VBA Code creates a User Account with the User Name: SMITHJOHN, with the Personal ID: SJ78901, and with an initial Password: SMITHJOHN:

Public Function CreateUsers()
'---------------------------------------------------------------------------------
'Author : a.p.r. pillai
'Date   : Feb-2010
'All Rights Reserved by www.msaccesstips.com
'Other Ref: http://www.msaccesstips.com/2006/11/create-msaccess-user-account/
'---------------------------------------------------------------------------------
Dim wsp As Workspace
Dim newUser As User, tempGrp As Group
Dim UsrName As String, PersonalID As String
Dim Password As String

On Error Resume Next

Set wsp = DBEngine.Workspaces(0)

    UsrName = "SMITHJOHN" ' 1 to 20 characters.
    PersonalID = "SJ78901" 'upto 4 to 20 alphaumeric characters
    Password = "SMITHJOHN" 'upto 14 characters except NULL

'Create User Account with personalID
   Set newUser = wsp.CreateUser(UsrName, PersonalID, Password)
   wsp.Users.Append newUser

   If Err = 3390 Then
      MsgBox "User Name : " & UsrName & vbCr & vbCr & "User PID    : " & PersonalID & vbCr & vbCr & "Account Name already Exists..! "
      Err.Clear
      Exit Function
   End If
   wsp.Users.Refresh

'Users Group must be created and joined the
'User to it. When created manually this step
'(for Users Group)is done automatically.
   With wsp
     Set tempGrp = .Users(UsrName).CreateGroup("Users")
         .Users(UsrName).Groups.Append tempGrp
         .Users.Refresh
   End With

End Function

When we create a User ID, we can set a password manually for the User.  After opening a new MS-Access Application window, select the Menu Options Tools ->Security ->User and Group Accounts ->, log in without a password, select the Change Logon Password Tab of the Dialog Control, and set a new password.

  1. Copy and paste the above Code into a Standard Module and save it.

  2. Click in the middle of the Code and press F5 to run the Code and create the User Account in the active Workgroup Information File.

  3. Select Tools - ->Security- ->User and Group Accounts and check for the User Name SMITHJOHN on the list.

The User Names are in alphabetical order.

Check for a Particular UserName with VBA.

We can check for the presence of a particular User Name in the active Workgroup Information File with the following VBA Code:

Public Function Check4UserAccount(ByVal strUsrName As String) As Boolean
'------------------------------------------------------------------------
'Author : a.p.r. pillai
'Date   : Feb-2010
'All Rights Reserved by www.msaccesstips.com
'------------------------------------------------------------------------

Dim WS As Workspace, msg As String
Dim UsrName As String, K As User, Flag As Boolean

Set WS = DBEngine.Workspaces(0)

'All the Users belong to the Common Group 'Users'
Flag = False
With WS.Groups("Users")
        For Each K In .Users
                  If K.Name = strUsrName Then
                          Flag = True
                          Exit For
                  End If
        Next
End With

If flag Then
     MsgBox "User Name: " & strUsrName & " Already Exists! "
End If

Check4UserAccount = flag

End Function

Type the following in the Debug Window (Immediate Window) and press the Enter Key to run the above Code:

Check4UserAccount "SMITHJOHN"

If you have not run the first program to create the User Account SMITHJOHN, then to test the second Program, call the above function with the Admin User Name.

Type the following in the Debug Window (Immediate Window) and press Enter Key:

Check4UserAccount "Admin"

Earlier Post Link References:

Share:

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

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