ACC2000: How to Use Animation ActiveX Control in Access (209919)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q209919
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article shows two examples of how to use the Animation ActiveX Control in a Microsoft Access database. The Animation ActiveX Control ships with Microsoft Office Developer Edition Tools.

MORE INFORMATION

With Animation ActiveX Control, you can play .avi files on a Microsoft Access form. When you open the form in Design view, you can see the control; however, in Form view, the control is hidden until you play the .avi file associated with the control. One common use for the animation control is to provide animation with command buttons. If you place the animation control on top of a command button and use the Click event of the button to invoke the Open and Play methods of the animation control, the button appears to be animated.

The Animation ActiveX Control supports only two types of .avi files: uncompressed .avi files, and .avi files that have been compressed using Run-Length Encoding. Sound components of .avi files are not played.

If you use an unsupported file format with the animation control, you receive the following error message:
Unable to Open AVI File

Example 1: Using the Animation Control to Animate a Command Button

  1. Start Microsoft Access and create a new blank database called Animate.mdb.
  2. Create a new form not based on any table or query in Design view.
  3. On the Insert menu, click ActiveX Control.
  4. In the Insert ActiveX Control dialog box, select Microsoft Animation Control, version 6.0, and then click OK.
  5. Set the following properties for the animation control:
       Animation control
       -----------------
       Name: an1
       Visible: No
       Left: 1"
       Top: .5"
       Width: 1"
       Height: 1"
    					
  6. Add a command button to the form, and set the following properties:
       Command button
       --------------
       Name: cmd1
       Caption: Play Animation
       Left: 1"
       Top: .5"
       Width: 1"
       Height: 1"
       OnClick: [Event Procedure]
    					
  7. Type the following code in the command button's OnClick event procedure:
    Private Sub cmd1_Click()
    Dim AviFile As String
    
    ' Type the full path to the .avi file on the following line.
    AviFile = "path and filename"
    
       With an1
          .Visible = True
          .AutoPlay = True
          .Open AviFile
       End With
    End Sub
    						
    NOTE: For the code to run properly you must insert the correct path and filename of your .avi file.
  8. Save the form as frmAnimate, and then switch to Form view.
  9. Click the command button and note that the .avi file plays on top of the command button.

Example 2: Selecting and Playing an Animation File

  1. Follow steps 1 through 3 in Example 1.
  2. On the Insert menu, click ActiveX Control.
  3. In the Insert ActiveX Control dialog box, select Microsoft Animation Control, version 6.0, and then click OK.
  4. Set the Name property of the animation control to An2.
  5. On the Insert menu, click ActiveX Control.
  6. In the Insert ActiveX Control dialog box, select Microsoft Common Dialog Control 6.0, and then click OK.
  7. Set the Name property of the common dialog control to Cd2.
  8. Add a command button to the form, and set the following properties:
       Command button
       --------------
       Name: cmd2
       Caption: Select & Play
       OnClick: [Event Procedure]
    					
  9. Type the following code in the command button's OnClick event procedure:
    Private Sub cmd2_Click()
       With Cd2
          .Filter = "avi (*.avi)|*.avi"
          .ShowOpen
       End With
       With An2
          .AutoPlay = True
          .Open Cd2.FileName
       End With
    End Sub
    					
  10. Save the form as frmSelectPlay, and then switch to Form view.
  11. Click the command button.
Note that an Open dialog box appears and lets you select an .avi file, and then the .avi file plays on the form.

REFERENCES

For more information about ActiveX Controls, click Microsoft Access Help on the Help menu, type ActiveX in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MajorLast Reviewed:6/24/2004
Keywords:kbhowto kbprogramming kbusage KB209919