ACC: Using OLE Automation to Change a Graph's Type

Last reviewed: August 29, 1997
Article 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 describes 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" (without the quotation marks).

  7. Add an option group to the form. Set the option group's Name property to "Graph_Type" (without the quotation marks).

  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."


Additional query words: graph5
Keywords : AutoGrph kbole kbusage FmsHowTo
Version : 2.0 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 29, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.