ACC: How to Use OLE Automation to Change a Graph's Type
ID: Q120418
|
The information in this article applies to:
-
Microsoft Access versions 2.0, 7.0, 97
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.
- Add an option group to the form. Set the option group's Name property
to Graph_Type.
- 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
- 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
- View the form in Form view.
- 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."
Additional query words:
graph5
Keywords : kbole kbusage FmsHowto
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbinfo