Microsoft KB Archive/120418

= ACC: How to Use OLE Automation to Change a Graph's Type =

Article ID: 120418

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



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:

 Open the sample database Northwind.mdb (or NWIND.MDB in Microsoft Access 2.0) 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. In the Available Fields box, select Ten Most Expensive Products, click the ">" button, select Unit Price, and then click the ">" button. Click the Next button twice, and then click the Finish button. View the form in Design view. Set the embedded graph's Name property to MyGraph .</li> Add an option group to the form. Set the option group's Name property to Graph_Type .</li>  Add the following six toggle buttons to the option group: <pre class="fixed_text">      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 </li>  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 </li> View the form in Form view.</li> Click the various toggle buttons. Note that the chart changes to match your selection.</li></ol>

<div class="references_section">