ACC2000: How to Use Automation to Change a Graph's Type (210344)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210344
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies only to a Microsoft Access database (.mdb).

SUMMARY

This article shows you how to use Automation to dynamically change a chart's type. For example, you can use this method to change a bar chart to a column chart as you print a report or view records in a form.

MORE INFORMATION

To use Automation to change a chart's type at run time, follow these steps:
  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Create a new form based on the Ten Most Expensive Products query. On the Insert menu, click Chart, and then insert a new chart in the form.
  3. In the Which Table or Query Would You Like to Use to Create Your Chart box, select the Ten Most Expensive Products query, and then click Next.
  4. Select the two available fields and click Finish.
  5. Set the embedded graph's Name property to MyGraph.
  6. Add an option group to the form, and then add the following six option buttons to the option group:
       Name: Area
          OptionValue: 1
       Name: Bar
          OptionValue: 2
       Name: Column
          OptionValue: 3
       Name: 3D_Area
          OptionValue: -4098
       Name: 3D_Bar
          OptionValue: -4099
       Name: 3D_Column
          OptionValue: -4100
    					
  7. Set the option group's Name property to Graph_Type and the option group's AfterUpdate property to the following event procedure:
    Private Sub Graph_Type_AfterUpdate()
       Me![MyGraph].Object.Application.Chart.Type = Int(Me![Graph_Type])
    End Sub
    					
  8. View the form in Form view.
  9. Click the various toggle buttons.

    Note that the chart changes to match your selection.

REFERENCES

For more information about using Automation, 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.

For more information about using Charts, click Microsoft Access Help on the Help menu, type create a chart in a form or report in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

Modification Type:MinorLast Reviewed:7/15/2004
Keywords:kbhowto kbusage KB210344