ACC2000: How to Use Automation to Rotate a Three-Dimensional Chart (210019)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210019
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 you how to use Automation to rotate a chart created in Microsoft Graph.

NOTE: Only graphs of the three-dimensional type can be rotated.

MORE INFORMATION

You can use Automation to programmatically rotate a graph. By using the Rotation property, you can rotate a three-dimensional graph to change the viewpoint of a graph or to provide an animated effect.

To rotate a three-dimensional pie graph a full 360 degrees, follow these steps:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

  1. Start Microsoft Access, and then open the sample database Northwind.mdb or the sample project NorthwindCS.adp.
  2. Open a new, blank form in Design view.
  3. On the Insert menu, click Chart. Click and drag a chart to the form.
  4. In the first dialog box of the Chart Wizard, under View, click Queries, and then select the Category Sales for 1997 query. Click Next.
  5. In the next dialog box, add the CategorySales and CategoryName fields to the Fields for Chart box. Click Next.
  6. In the next dialog box, click 3-D Pie Chart, and then click Finish. Your graph now appears on the form.
  7. On the View menu, click Properties. Select the graph so that you are viewing the Graph object's properties. Set the Name property to MyGraph.
  8. Add a command button to the form with the following properties:

    Caption: Rotate Graph
    OnClick: =RotateGraph()

  9. Click the form, and then, on the View menu, click Code to view the form's module.
  10. Add the following code to the form's module:
    Function RotateGraph()
    Dim OldRotation As Integer
    Dim NewRotation As Integer
    Dim GraphObj As Object
    Set GraphObj = Me![MyGraph].Object.Application.Chart
    
    ' Determine the initial rotation setting.
    OldRotation = GraphObj.Rotation
    
    ' Rotate graph from initial setting to 360 degrees.
    For NewRotation = OldRotation To 360 Step 12
       GraphObj.Rotation = NewRotation
       If GraphObj.Rotation = 360 Then GraphObj.Rotation = 0
       DoEvents
       DoCmd.RepaintObject
    Next
    End Function
    					
  11. Switch the form to Form view. Click the command button to make the graph rotate 360 degrees.

REFERENCES

For more information about Automation, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type understanding automation in the Office Assistant or the Answer Wizard, and then click Search to view the topic.


Modification Type:MajorLast Reviewed:6/29/2004
Keywords:kbhowto kbinterop KB210019