ACC: How to Use OLE Automation to Change a Graph's Type (120418)



The information in this article applies to:

  • Microsoft Access 2.0
  • Microsoft Access for Windows 95 7.0
  • Microsoft Access 97

This article was previously published under Q120418

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

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

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access 2.0. For more information about Access Basic, please refer to the "Building Applications" manual.

MORE INFORMATION

The following example demonstrates how to use Automation to change a chart's type at run time:

  1. Open the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0)
  2. Create a new form based on the Ten Most Expensive Products query. Click "Chart Wizard" in the list box and click OK.

    NOTE: In Microsoft Access version 2.0, click the Form Wizards button and click Graph in the "Which wizard do you want?" dialog box.
  3. In the Available Fields box, select Ten Most Expensive Products, click the ">" button, select Unit Price, and then click the ">" button.
  4. Click the Next button twice, and then click the Finish button.
  5. View the form in Design view.
  6. Set the embedded graph's Name property to MyGraph.
  7. Add an option group to the form. Set the option group's Name property to Graph_Type.
  8. Add the following six toggle 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
    						
  9. Set the option group's AfterUpdate property to the following event procedure:
           Sub Graph_Type_AfterUpdate ()
              Me![MyGraph].Object.Application.Chart.Type = Int(Me![Graph_Type])
           End Sub
    						
  10. View the form in Form view.
  11. Click the various toggle buttons. Note that the chart changes to match your selection.

REFERENCES

For more information about using Automation, type Automation in the Office Assistant, click Search, and then click to view "Automation with Microsoft Access."

For more information about using Charts, type Charts in the Office Assistant, click Search, and then click to view "Create a Chart."

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbinfo kbProgramming kbusage KB120418