Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

Showing posts with label Animations. Show all posts
Showing posts with label Animations. Show all posts

Creating Animated Command Button with VBA

Introduction.

The first blog post that I have written about is the Command Button Animation method in September 2006 on this Web site.  I used this animation method in almost all my Projects.  The command buttons responding to the mouse moves over them presented a sense of life to the Forms, which otherwise remained rigid and boring.  The Command Button and a Rectangle control set with shadow special-effect designed manually. 

The Mouse_move() Event Procedures in the form are written manually to call a Function to do the job of animation.  I suggest you go through the earlier blog post to get a general idea before continuing.  To go to the earlier Article click here.

Now, we will see how to create the Animated Command Button with its animation programs (for each button) on the Form Module, during Form design time with the click of a button.

Animated Button Creation Code.

With two VBA routines, we can do this very easily.

  1. Open one of your databases.

  2. Display the Standard VBA Module.

  3. Create a new Standard Module (Insert - - > Module).

  4. Copy both the following Functions into the Standard Module and save the code:

Command Button Animation Code:

Public Function BAnimate(ByVal strForm As String, ByVal mode As Integer, ByVal lblName As String)
'---------------------------------------------------------------------------
'Author : a.p.r. pillai
'Date   : July 1998
'Remarks: Animates the Command Button
'Rights : All Rights Reserved by www.msaccesstips.com
'---------------------------------------------------------------------------
Dim Frm As Form, l As Long, t As Long

On Error GoTo BAnimate_Err

Set Frm = Forms(strForm)

l = Frm.Controls(lblName & "Box").Left
t = Frm.Controls(lblName & "Box").Top

If (mode = 1) And (Frm.Controls(lblName & "Box").Visible = False) Then
    Frm.Controls(lblName & "Box").Visible = True
        Frm.Controls(lblName).Left = l - (0.0208 * 1440)
        Frm.Controls(lblName).Top = t - (0.0208 * 1440)
        Frm.Controls(lblName).FontWeight = 700
ElseIf (mode = 0) And (Frm.Controls(lblName & "Box").Visible = True) Then
    Frm.Controls(lblName & "Box").Visible = False
        Frm.Controls(lblName).Left = l
        Frm.Controls(lblName).Top = t
        Frm.Controls(lblName).FontWeight = 400
End If

BAnimate_Exit:
Exit Function

BAnimate_Err:
Err.Clear
Resume BAnimate_Exit

End Function

Animated Command Button Creation Code:

Public Function CreateButton(ByVal intSection As Integer, strName As String)
'---------------------------------------------------------------------------
'Author : a.p.r. pillai
'Date   : Aug. 2000
'Remarks: Creates animated command button controls and Programs on a Form
'       : at design time of the form.
'Rights : All Rights Reserved by www.msaccesstips.com
'---------------------------------------------------------------------------
'Program Parameter Values : intSection
'     0 =  Form Detail Section
'     1 =  Form Header Section
'     2 =  Form Footer Section
'                         : strName
'Command Button Name Property Value
'The Name will be prefixed with the text 'cmd'
'Example: Edit will be modified as cmdEdit
'Sample Run : CreateButton 0,"Edit"
'Remarks    : If more than one Form is opened in Design View then the
'           : Command Button will be created on the first Form
'---------------------------------------------------------------------------
Dim Frm As Form, Ctrl As Control, txt As String
Dim vLeft As Long, vTop As Long, vWidth As Long, vHeight As Long
Dim i As Long, dif As Double, x As Long, Y As Long, z
Dim frmViewStatus As Integer, frmsCount As Integer, j As Integer
Dim hfd As String
On Error Resume Next

i = 1440
dif = 0.0208 * i
vLeft = 0.25 * i
vTop = 0.0521 * i
vWidth = 1.25 * i
vHeight = 0.2375 * i

frmsCount = Forms.Count - 1
frmViewStatus = False
For j = 0 To frmsCount
    If Forms(j).CurrentView = 0 Then
      Set Frm = Forms(j)
      frmViewStatus = True
      Exit For
    End If
Next
If frmViewStatus = False Then
   MsgBox "Open a Form in Design View then try again." & vbCr & vbCr & "Program CreateButton() Aborted."
   Exit Function
End If

  Set Ctrl = CreateControl(Frm.Name, acRectangle, intSection, , , vLeft, vTop, (vWidth - dif), (vHeight - dif))
  
  With Ctrl
    .Name = "cmd" & strName & "Box"
    .SpecialEffect = 4
    .BorderWidth = 3
  End With

  Set Ctrl = CreateControl(Frm.Name, acCommandButton, intSection, , strName, vLeft, vTop, vWidth, vHeight)
  
  With Ctrl
    .Name = "cmd" & strName
    .Caption = strName
  End With
   
  x = Frm.Module.CreateEventProc("MouseMove", Ctrl.Name)
  
  txt = "BAnimate me.name, 1, " & Chr(34) & "cmd" & strName & Chr(34)
  Frm.Module.InsertLines x + 1, txt

  hfd = Choose(intSection + 1, "Detail", "FormHeader", "FormFooter")

  z = Frm.Module.ProcBodyLine(hfd & "_MouseMove", vbext_pk_Proc)

  If z = 0 Then
      x = Frm.Module.CreateEventProc("MouseMove", hfd)
  Else
      x = z + 1
  End If

  txt = "BAnimate me.name, 0, " & Chr(34) & "cmd" & strName & Chr(34)
  Frm.Module.InsertLines x + 1, txt


CreateButton_Exit:
Exit Function

CreateButton_Err:
Resume CreateButton_Exit
End Function

Press Ctrl+S to save the programs. Keep the VBA Window open.

Do the Test Run.

Now that you have the main functions for creating and animating Command Buttons, let us do a quick run to see how easy it is.

  1. Close all open forms, if any.

  2. Open a new Form in Design View.

  3. Display the VBA window, if it was closed or minimized (Alt+F11).

  4. Display the Debug Window (Immediate Window) - Ctrl+G.

  5. Type the following statement in the Debug Window and press Enter Key:

CreateButton 0,"Edit"
  • The first Parameter value 0, represents the Form's Detail Section (0=Detail, 1=Form Header, 2=Form Footer), where we want the Command Button to appear.

  • The second parameter “Edit” is the Command Button's Name (will be modified as cmdEdit and set in the Name property) and Caption value. The second parameter must be always a single word. This is absolutely necessary to create the MouseMove Event Procedure correctly on the Form's Module. The Caption of the Command Button can be changed later, if necessary.

  1. Minimize the VBA window to show the Form in Design View.  You can see the Command Button is created in the Detail Section of the Form with the Caption Edit.

  2. Change the Form into Form View.

  3. Move the Mouse over the Command Button.  The button moves up a little and to the left to show a shadow at the bottom and to the right of the Command Button.

  4. Move the mouse out of the button.  The Command Button settles back to the original position hiding the shadow.

  5. Repeat this action in quick succession.  You can see the movement of the button more clearly.

    The VBA Code is Written by the Program.

    If you display the Form's VBA Module you can see that the following VBA Program lines are written into it:

    Private Sub cmdEdit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
         BAnimate Me.Name, 1, "cmdEdit"
    
    End Sub
    
    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        BAnimate Me.Name, 0, "cmdEdit"
    
    End Sub
  6. Change the Form mode to Design View again.

  7. Click on the Command Button to select it.

  8. Drag the Command Button to the right and down to show the Rectangle Control with the special effect shadow underneath it.

    The Command Button and the Rectangle Control together make the animation trick.  Click somewhere near the Command Button and drag the Mouse over it to select them together and drag them to the intended location. Do this before you attempt to create another Command Button in the same section of the Form, otherwise, the next one will be created and placed over the earlier one.  New Command Buttons are always created in the same location in the Form Section.

  9. Right-Click on the Detail Section of the Form and select Form Header/Footer to display them on the Form.

Creating Button on Header or Footer Section.

Now, you may try the CreateButton() Function with the first parameter value 1 or 2 to create Command Buttons in the Form Header or Form Footer Sections respectively.  The Second parameter, the Name of the Command Button must be different for all Command Buttons on the same Form.  Sample statements for creating Animated Command Buttons on the Header and Footer of the Form are given below:

CreateButton 1, "PrintPreview"

CreateButton 2, "Exit"

NB: Keep the Header/Footer Sections visible before you attempt to create Command Buttons on them.  There should not be more than one form in Design View.  Otherwise, the first form found in the design mode will be selected for creating the button controls.

During the design time of the form running the CreateButton() Function from the Debug Window is the most convenient method.  But, if you look for something different like launching the program from a Command Button Click then we can do that too. 

Button Creation from a Command Button Click.

We can create a Command Button on a Form to click and input parameter values for the button creation program and quickly create it on the Form currently in Design View and build its Sub-Routines on the Form Module as well.

  1. Open a new Form in Design View.

  2. Create a Command Button as you do normally.

  3. Display its Property Sheet when the Command Button is in the selected state (F4).

  4. Change the Name property value to cmdCreate and set the Caption property value to Create Button.

  5. Display the Form's VBA Module (Alt+F11).

  6. Copy and Paste the following Code into the Module and press Ctrl+S to save the Form with the name frmCreateButton:

    Private Sub cmdCreate_Click()
    Dim intSection As Integer, strButtonName As String
    Dim msg As String
    msg = "Form Section (0,1 or 2)" & vbCr
    msg = msg & "0 - Form Details" & vbCr
    msg = msg & "1 - Form Header" & vbCr
    msg = msg & "2 - Form Footer"
    
    intSection = 3
    Do While intSection < 0 Or intSection > 2
        intSection = Nz(InputBox(msg, "cmdCreate_Click()"), 0)
    Loop
    
    strButtonName = ""
    Do While Len(strButtonName) = 0
        strButtonName = InputBox("Command Button Name", "cmdCreate_Click()")
    Loop
    
       If (intSection >= 0 And intSection < 3) And Len(strButtonName) > 0 Then
           CreateButton intSection, strButtonName
       End If
    
    End Sub

    Perform a Demo Run

  7. Open a form in Design View and display the Form’s Header/Footer Sections.

  8. Open the frmCreateButton in Normal View.

  9. Click on the Command Button to enter the parameter values of the program.

  10. Input one of the values (0, 1, or 2) suggested by the Prompt to select a Section of the Form and press the Enter Key or Click OK button.

  11. Enter a Name for the Command Button in the second prompt (it should be a single word like PrintPreview) and press Enter Key or Click OK.

  12. The Command Button controls are created on the selected Section of the form you kept open in the design view.

If you want to use this method on all your Projects then you may transfer the first two Functions (BAnimate() and CreateButton()) Codes into a common Library Database and attach them as Reference Library File (refer to the Blog Post Command Button Animation to know how to do this) to your Projects.

  1. Command Button Animation
  2. Double Action Command Button
  3. Colorful Command Buttons
  4. Transparent Command Button
  5. Command Button Animation-2
  6. Creating Animated Command Button with VBA
  7. Command Button Color Change on Mouse Move

Share:

Lively Controls on Form

Introduction

We always concentrate on the timely completion of a project and delivering it to the User as quickly as possible.  I will try to keep up with the schedule and deliver the project for testing to the User.  But all the time I would like to have a second look at the overall design and appearance of the Forms and Reports in a relaxed atmosphere and bring in some improvements with whatever new tricks that I can think of at that point in time, besides incorporating the requirements suggested by the user.

In my past experience with this kind of trick, I have been always rewarded with appreciation from the Users. Their responses to these little things that I have incorporated into the design always encouraged me to look for something different next time.  Forms are the main component of any Application that catches the eye of the Customers besides nicely formatted Reports and impressive Graph Charts.

Forms have a special place in the minds of the User. It should be pleasing to look at and user-friendly to work with.  Once the initial pressure of designing the main components of an application is over and if you have enough time to have a second look at the main forms' design you can make use of your creative ideas and pull little tricks on the Form that will do wonders. All the controls we draw on the Microsoft Access Forms remain stationary forever.  If we can put some action or movement, in some controls, without overdoing it, it will definitely have some positive impact on the Customers.

We have learned several animation tricks on controls in the past and If you would like to take a second look at them, then their links are given below:

  1. Command Button Animation
  2. Reminder Ticker Form
  3. Startup Screen Design
  4. Animated Floating Calendar
  5. Wave Shaped Reminder Ticker
  6. Command Button Animation-2
  7. Animating Label on Search Success
  8. Run Slide Show when Form is Idle
  9. Label Animation Style-1
  10. Label Animation Style-2
  11. Label Animation Variant
  12. Label Animation Zoom in Style
  13. Label Animation in Colors
  14. Label Animation Zoom-out Fade
  15. Digital Clock on Main Switchboard

Option Group Control Style Change on Mouse Move.

Here, we will do a simple trick on an Option Group Control to respond, when the mouse moves over it for the selection of options.  The trick is simple, when the Option Group control is created we will give it a Raised Style design.  When the mouse moves over the Option Group control the Style will change to Sunken.  When the mouse moves away from the Option Group control it will go back to its earlier Raised state.  The repetition of this action gives a lively look at the Option Group control.

Create a Form for Demo.

  1. Open a new Form in Design View.

  2. Click on the Wizard Button (with the magic wand icon) on the Toolbox to select it, if it is not already in the selected state.

  3. Select the Option Group control and draw it on the detail section of the form.

  4. Enter the options as shown on the design below by pressing the Tab key after each option to advance to the next row. You may enter any Text as options as you like.

  5. Complete the design by selecting the Finish Command Button.

  6. Move the attached label above and make it as wide as the Option Group Control and change its Caption to Main Menu.

  7. Move the attached child label above and make its width the same as the Option Group control and align it to the left edge. 

  8. Change the Caption of the label to Main Menu.

  9. Click on the Option Group to select it and display its Property Sheet (View - -> Properties or press ALT+Enter).

  10. Change the following Property Values as given below:

    • Name = Frame0

    • Back Style = Normal
    • Special Effect = Raised

    The Form's Class Module Code.

  11. Display the VBA Code Module of the Form (View - ->Code or click on the Module Toolbar Button or press ALT+F11).

  12. Copy and Paste the following VBA Code into the VBA Module of the Form:

    Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
       If Me.Frame0.SpecialEffect <> 1 Then
           Me.Frame0.SpecialEffect = 1
       End If
    End Sub
    
    Private Sub Frame0_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
       If Me.Frame0.SpecialEffect <> 2 Then
           Me.Frame0.SpecialEffect = 2
       End If
    End Sub
  13. Save and close the Form.

    The Demo Run.

  14. Open the Form in the normal view.  You will find the Option Group control is in Raised style.

  15. Move the mouse over the control and it will enter into the Sunken state.

  16. Move the mouse pointer away from the control and it will restore back to the Raised state.

  17. Repeat this action in quick succession and you can see how the Option Group control responds to this simple action, otherwise, the control remains rigid forever.

Technorati Tags:
Share:

Digital Clock on Main Switchboard

Introduction

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 the current time when the Main Switchboard becomes 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.

Simple Clock Design.

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 - Northwind. 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 the 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 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 the VBA Sub-Routine as given below:

    The Form_Load() Event and Code.

    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 three lines of the 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 the Current Date and Time and the 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

    Trial Run of Form Activity.

  4. Save the Form and Close it.

  5. Open it in the normal view.

  6. Open some other Forms 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 becomes active and the Clock will start updating the Date/Time again.

Technorati Tags:
Share:

Label Animation Zoom-out Fade

Introduction.

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's name is slowly fading away in the distance. The size of each letter of the name is getting reduced at each step and the letters are displayed at a fixed time interval giving it an animated and three-dimensional effect.

Links to earlier Animation Styles.

If you have not tried out the earlier Label animation methods you may take a look at 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 have used last week with twenty small labels with the Name Property set with the Values lbl01 to 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 Code Module of the Form (View - -> Code).

  4. Copy and paste the following VBA Code into the Module, over-writing 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 Button and move the record forward or back and watch how the Employee name is displayed on the header of the form.

  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

Introduction.

We have learned several label animation methods, through the 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 colors generated randomly. Besides that, the name of the employee is plotted in a magical way by displaying odd-numbered letters first on odd-numbered labels i.e. lbl01, lbl03, lbl05, and even-numbered letters displayed on 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 this two-step action, 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.

The Design Task.

  1. Make a Copy of the Employees Form, which we have 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 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.

    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 character of the name will be displayed in different colors and in one-tenth of a millisecond 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.

  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

Introduction.

This week we will learn a different style of Label Animation technique. For 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.

The employee name will appear from left to right, character by character on 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.

The Design Task.

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 the Northwind 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
    • 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. 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.

    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 also and name them as lbl03, lbl04, and so on up to lbl20.

  16. Click on the left side of the first label (lbl01) and drag the Mouse over all the twenty 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 set 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 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 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.

  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

Introduction.

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

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

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

The change is required only on the position of the second label lbl2. The arrangement of labels of the last animation method 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 is reduced and place them a little bit closer so that the animation style has 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. 

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 the Employee2_1 in Design View.

  3. Click on lbl2 (the label with the White-colored 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 the change in the 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
    • 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 over-writing 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:

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-colored 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
    • ForeColor = #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.

    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
    
    
  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 the 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

Introduction

Last week we learned a simple label animation method to display Employee Names, and made them appear character by character from the right side of the label to full view. The animated label gives the Form a lively look and makes it more interesting for the  User to work with the Screen.

This week we will learn a different label animation method with the same set of labels. In the earlier method, we used two identical labels to give the employee name a 3D effect.  We will stick with the same design, but the labels will be put horizontally apart in the design as shown below:

In the Current-Event Procedure of the Form the Labels will be moved in the opposite direction and finally assembled into a 3D heading style as shown below:

This happens every time an employee record becomes current.  The labels will restart from their original design position and slowly move in the opposite direction and stay in place to form the 3D Style Employee Name.

If you have gone through the earlier label animation design task, then it is easy to implement this one very easily.  All you have to do is to set the following Property Settings of lbl1 and lbl2 and copy the VBA routines into the Employee Form 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 name it Employee2.

  3. Open the Employee2 Form in Design View.

  4. Click on the top label on the header of the Form and drag and move it to the right so that we will be able to click and select the labels individually and set their properties.

  5. Select the Label with the name 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 with the name 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 Code Module of the Form (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

Introduction

A Form with lively Objects like Animated Command Buttons, Animated GIFs, Moving Text, etc., makes it more interesting for the User to work with MS-Access Applications.  MS-Access doesn't have any of those things built-in or ready-made to use quickly. Our imagination and ingenuity is the only tool available to create something with the existing, strictly for business-like features in MS-Access.

After working with MS-Access for some time I got bored with the repeated use of the same objects without any changes for designing the Applications.  I wanted to make something more eye-catching to kill the boredom. As the saying goes "Necessity is the father of inventions", I have developed some interesting features like Command Button Animation, Animated Floating Calendar, usage of Office Assistant in MsgBoxes, Animating Label on search success, Reminder Ticker, and others.

Today we will learn a simple Label Animation Technique with an example in the Employees Form from 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 can see that the Employee's; Name; Firstname and Lastname joined together; is displayed in the Header of the Form in a Text Box. When you make some other record current on 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 the right edge of the label to the left, character by character, and move 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 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 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 you will find the Employee Name is moving into place slowly from right to left, character by character, in the header label.

  12. Click on the Navigation button to move the records forward one by one.
  13. The names of the employees 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 little fancy work to the Employee Name with a three-dimensional backlit effect by copying the Label and placing it over the existing one. See the finished design of the image is given below:

  1. Open the Employee Form in Design View.

  2. Select the header label.

  3. Click on the Copy, Paste ToolBar buttons to make a copy of the label (or select Copy, Paste Options from the View Menu).

  4. Click on the new Label to select it, if it is not in the selected state.

  5. Display the Property Sheet of the Label (View - ->Properties).

  6. Change the following Property Values as shown below:

    • Name = lbl2
    • ForeColor = 128
  7. 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:

  8. 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:

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

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

  11. 'Me.lbl2.Caption = txt2

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

  13. Save and Close the Form.

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

  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:

Run Slide Show when Form is Idle

Introduction

This week, we will create a Slide Show of images on a Form that runs when the Form remains idle for a certain period of time.  It works something like the following:

  • When the Main Switchboard Form remains idle for about one minute the Slide Show runs and each image will change at a fixed interval of about 6 seconds. The Idle Time and Interval Time can be changed according to your specific needs.

  • The idle time of the Form is calculated based on the inactivity (i.e. No interaction with the User) of the Main Switchboard Form and the active control on the Form remains active for more than one minute.

  • If you click on a Command Button or List box or any other control other than the active control on the Main Switchboard Form then the Form comes out of its idle state and the Slide Show stops.

  • Checking for the idle state of the Form starts again from that point onwards with the new active control. If the same control remains active for more than one minute then the slide show starts again.

  • If you open another Form over the Main Switchboard Form then the slide show sleeps until the Main Switchboard Form becomes active again.

  • You need a few Bitmap Images of Landscapes or Photos and you can use as many images as you like for the Slide Show. All the images should have the same name with a Sequence Number at the end like 1.bmp, 2.bmp, 3.bmp, and so on. You can use jpg or gif and other images but this will display a progress bar for a brief moment while loading the image into the Image Control. All images must be of the same type.

Sample Main Switchboard Form

A sample Main Switchboard Form with the active Slide Show is given below:

Click to Enlarge


The Design Task

  1. To try out this interesting trick; first, organize a few Bitmap Images into a folder as explained above.

  2. Make a copy of your existing Main Switchboard Form (Control Screen).

  3. Open the Form in Design View.

  4. Make enough room on the Form to create an Image Control on the Form.

  5. Display the Toolbox (View - - >Toolbox), if it is not visible.

  6. Select the Control Wizards button on the Toolbox to make it active.

  7. Select the Image control Tool from the Toolbox and draw an Image Control on the Form where you want the SlideShow to appear.

  8. The Common Dialog Control will display. Browse to the Image location and select the image with Serial Number 1 (Image1.bmp).

    The selected image will appear in Image Control.

  9. While the Image control is still in the selected state; display the Property Sheet (View - -> Properties) and change the following Property Values as indicated below:

    • Name = ImageFrame

    • Size Mode = Zoom

    NB: We need part of the Picture Property Value (the location address of the Images) to make changes in the Program that we are going to introduce into the Code Module of the Form. So, note down the image location address on paper from the Picture Property or copy and paste it into a Notepad document for later use.

  10. Display the Code Module of the Form (View - -> Code).

  11. Press Ctrl+A to highlight the existing VBA Code in the Module, if present, and press Delete to remove them.

  12. Copy and Paste the following Code into the Form Module.

    Switchboard Form Module VBA Code (Revised Code)

    Option Compare Database
    
    Dim actForm As String, actControl As String, idletime As Integer
    Dim oldForm As String, oldControl As String, imageNo As Integer
    Dim s_path As String
    
    Private Sub Form_Activate()
        Me.TimerInterval = 1000
    End Sub
    
    Private Sub Form_Deactivate()
        Me.TimerInterval = 0
        Me.ImageFrame.Visible = False
    End Sub
    
    Private Sub Form_Load()
    DoCmd.Restore
    idletime = 0
    imageNo = 0
    s_path = CurrentProject.Path
    Me.ImageFrame.Visible = False
    Me.TimerInterval = 1000
    End Sub
    
    Private Sub Form_Timer()
    Dim txt As String
    
    txt = "Slide-Show Starts In: "
    
    actForm = Screen.ActiveForm.Name
    actControl = Screen.ActiveForm.ActiveControl.Name
    
    If actForm = oldForm And actControl = oldControl And actForm = "SlideShow" Then
        idletime = idletime + 1
        
        If idletime > 15 And idletime < 31 Then
            
          Me.Lblup.Visible = True
          Me.Lblup.caption = txt & (30 - idletime) & " Seconds."
            
        Else
            Me.Lblup.Visible = False
        End If
    Else
        oldForm = actForm
        oldControl = actControl
        idletime = 0
        Me.ImageFrame.Visible = False
        Me.Employees.Visible = False
        DoEvents
    End If
    
    If idletime > 30 Then
        Me.Lblup.Visible = False
        DoEvents
       If idletime Mod 5 = 1 Then
            Me.ImageFrame.Visible = True
            Me.Employees.Visible = True
            imageNo = imageNo + 1
            imageNo = IIf(imageNo < 1 Or imageNo > 9, 1, imageNo)
            Me.ImageFrame.Picture = s_path & "\" & imageNo & ".bmp"
            
            DoEvents
       End If
    End If
    
    End Sub
    
    

    Make Important Changes to References

  13. Change the "SlideShow" reference in the VBA code line with your own Main Switchboard Form Name.

  14. Change Number 9, in the second line with bold letters, to match with the number of Images you have saved for the Slide Show as explained above.

  15. If your pictures are not Bitmap Images then change the file extension ".bmp" to indicate your image type.

  16. Save and Close the Form.

  17. Open the Main Switchboard Form in Normal View.

  18. Wait for one minute to begin the Slide Show.

Interrupting the Slide Show.

When the Slide Show is running, if you click on a Control other than the active control on the Form the Slide Show will stop and the image will disappear.

If you don't click on any other control on the Form and the time elapsed is more than 30 seconds, since your last click on a Control, the Slide Show will run again.

If you want to increase or decrease the idle time of the Form then change the value in the VBA line If idle time > 30 Then to an appropriate value you prefer.

Each Image stays displayed for about 6 seconds. If you want to increase or decrease the display time, then change the Value in the VBA line

If idle time Mod 5 = 1 Then to the required value you prefer the time delay between two slides for viewing.

Download the Demo Database from the Link given below:

NOTE: Unzip the Database with Photos into a Temporary Folder and open the Database from there. Read the Notes given in the Form for details on how it runs and how to disable it etc.

Share:

Office Assistant And Msgbox Menus-3

After Clickable Menu Options - Access 2003.

After going through the earlier Articles on this subject I hope that the Readers are now familiar with programming the Balloon Object of Microsoft Office Assistant. You have seen that you can use this feature with a few lines of customizable VBA Code to display MsgBox text formatted with Color, underline, and with your favorite images on them. We can display Menus on them to obtain responses from Users, besides the buttons that we normally use like OK, Cancel, Yes, No, etc.

Since this article is the third part of this series I suggest that new Readers may go through the earlier Documents on this subject to learn interesting and simple ways to use this feature in MS-Access before continuing with this Article. Links to those Articles are given below:

Last week we learned how to display Clickable Menu Options in Message Box with the use of Office Assistant. The Image of that example is given below.

We have displayed the Menu Options in the Message Box with the Labels Property of the Balloon Object of Office Assistant.

Check Box Menu Options

Here, we will learn how to display Menu Options with Checkboxes and how responses from the User can be obtained, examined, and execute actions that are programmed for each choice made. The example code and the sample image of MsgBox that displays the Check-Box Menu is given below:

Public Function ChoicesCheckBox()
Dim i As Long, msg As String
Dim bln As Balloon, j As Integer
Dim selected As Integer, checked As Integer

Set bln = Assistant.NewBalloon
With bln
    .Heading = "Select Data Output Option"
    .Checkboxes(1).text = "Print Preview."
    .Checkboxes(2).text = "Export to Excel."
    .Checkboxes(3).text = "Datasheet View."
    .Button = msoButtonSetOkCancel
    .text = "Select one of " & .Checkboxes.Count & " Choices?"
    i = .Show

    selected = 0
    If i = msoBalloonButtonOK Then
        'Validate Selection
        For j = 1 To 3
            If .Checkboxes(j).checked = True Then
                selected = selected + 1
                checked = j
            End If
        Next

       'If User selected more than one item
        'then re-run this program and force the
        'User to select only one item as suggested
        'in the message text.

        If selected = 0 or selected > 1 Then
           Call ChoicesCheckBox
        Else
            Select Case checked
                Case 1
                    Debug.Print .Checkboxes(checked).text
                Case 2
                    Debug.Print .Checkboxes(checked).text
                Case 3
                   Debug.Print .Checkboxes(checked).text
            End Select
        End If
    End If
End With

End Function

Like the Labels Property Array, the dimension of CheckBoxes also can be up to a maximum of five elements only.

In our earlier example, we have not used the OK or Cancel buttons along with the Labels based Menu because the Balloon Button (msoBalloonTypeButtons) based options were clickable and accepted the clicked item as a valid response and dismisses the Office Assistant on this action. The clicked item's index number is returned as the response value and it was easy to check this value and execute the action accordingly.


But in the case of Checkboxes, this is a little more complex because of the following reasons

  1. The CheckBoxes can be either in checked or in the unchecked state, which needs to be validated.
  2. The User may put check marks on one or more Options at the same time. If this cannot be allowed, then there must be a validation check and force the User to make the selection of one item only.
  3. If the User has the option of selecting more than one item then the program must be written to execute more than one action based on the combination of selections made.
  4. In either case, we have to inspect the checked or unchecked state of each element of the CheckBox Array to determine the validity of Menu selection.

Validating the Checked/Unchecked Items

In the example code given above the User can select only one item at a time.

  • In the validation check stage of the code, first, we are checking whether the User has clicked the OK Button or not.
  • If she did then in the next step we take a count of all check-marked items, in the Variable selected.
  • If the value in the Variable selected is zero (The User clicked the OK Button without selecting any option from the list) or selected more than one item then the Program is called again from within the ChoicesCheckBox() Function itself. This will refresh the Menu, removes the check marks, and display it again. This will force the user to make only one selection as suggested in the message or she can click Cancel Button.
  • In the next step, the action is programmed based on the selection made by the User.
  • If the User is allowed to put check marks on more than one item (depending on the purpose of the MessageBox-based Menu) then the validation check and the execution of actions can be different and the code must be written accordingly.

The methods which I have introduced to you and explained in these three Articles are good to learn the basics of this feature and easy to understand the usage of different Properties of Balloon Object of Office Assistant.

But, you will appreciate the fact that duplicating and customizing these Codes everywhere in your Programs for different needs is not advisable. This will increase the size of your database, no flexibility in usage of Code and it is not good programming practice either.

You may go through the Articles (links are given below) published earlier on this Subject that it shows, how to define Public Functions like MsgOK(), MsgYN(), MsgOKCL(), and others with the use of Office Assistant. It simplifies the usage of this feature, without duplicating the code, and can use them freely anywhere in your Programs like MS-Access MsgBox() Function.

The above Function Names themselves suggest what kind of Buttons will appear in the Message Box when they are called with the minimum Parameter Value of Message Text alone or Message Text and Title Values.

  1. Message Box using Office-Assistant
  2. Message Box with Options Menu
  3. Office Assistant with CheckBox Menu

A comparison of the above User Defined Function usage with the MsgBox is given below for reference. The underscore character in the text indicates the continuation of lines and should not be used when all values are placed on the same line.

MS-Access MsgBox() usage Office-Assistant-based User Defined Function usage
MsgBox "Welcome to Tips and Tricks"MsgOK "Welcome to Tips and Tricks"
X = MsgBox("Shut Down Application", vbQuestion+vbDefaultButton2+vbYesNo, _"cmdClose_Click()")X = MsgYN("Shut Down Application", _ "cmdClose_Click()")
X = MsgBox( "Click OK to Proceed or Cancel?", _ vbOKCancel+vbDefaultButton2+vbQuestion, _ "MonthEndProcess()")X = MsgOKCL("Click OK to Proceed or Cancel?", _
"MonthEndProcess()")

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 Class Module External Links Queries Array msaccess reports Accesstips WithEvents msaccess tips Downloads Objects Menus and Toolbars Collection Object MsaccessLinks Process Controls Art Work Property msaccess How Tos Combo Boxes Dictionary Object ListView Control Query VBA msaccessQuery Calculation 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 RaiseEvent Recordset Top Values Variables Wrapper Classes msaccess email progressmeter Access2007 Copy Excel Export Expression Fields Join Methods Microsoft Numbering System Records Security Split SubForm Table Tables Time Difference Utility WScript Workgroup 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 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