HOW TO: Use Automation to Change a Graph Chart Type in Access 2000 (210021)



The information in this article applies to:

  • Microsoft Access 2000

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

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

IN THIS TASK

SUMMARY

This article shows two methods that you can use to work with Microsoft Graph objects. One method demonstrates how to use Automation to change the chart type of a Microsoft Graph object. The second method shows how to determine the graph type.


You can use Automation to change the chart type of a Microsoft Graph object. However, changing a graph from one type to another automatically resets properties of the graph that do not apply to the new graph type. For example, trendlines apply to a Two Dimensional Column graph but not to a Pie chart. Therefore, changing the type from a Column to a Pie drops the trendlines.

back to the top

Example: Changing a Chart Type

The following example shows you how to produce a chart in the Northwind.mdb database and change a graph's chart type to 3-Dimensional Pie:
  1. Start Microsoft Access and open the sample database Northwind.mdb.
  2. Create a new form not based on any table or query in Design view.
  3. On the Insert menu, click Chart. Click and drag a chart onto the form.
  4. In the first dialog box of the chart wizard, on the View menu, click Queries, select Employee Sales By Country, and then click Next.
  5. In the next dialog box, add the Country and SaleAmount fields to the Fields For Chart box, and then click Finish.

    Your graph appears in the form.
  6. On the View menu, click Properties. Select the graph so that you are viewing the Graph object's properties. Set the Name property to MyGraph.
  7. Add a command button to the form with the following properties:

    Command button:
    -----------------
    Name: MyButton
    Caption: Pie Chart
    OnClick: [Event Procedure]

  8. On the View menu, click Code to view the form's module.
  9. On the Tools menu, click References, select Microsoft Graph 9.0 Object Library, and then click OK.
  10. Type the following procedure into the module:
    Sub MyButton_Click()
       Dim GraphObj As Object
    
       Set GraphObj = Me![MyGraph].Object.Application.Chart
       GraphObj.Type = xL3DPie
    End Sub
    					
    NOTE: To view other chart types in Visual Basic for Applications, click Object Browser on the View menu and search the Microsoft Graph object library for "Constants."

  11. Switch the form to Form view. When prompted for a beginning and ending date, type 1/1/97 and 1/1/98. Click the command button.

    Note that the chart changes to a three-dimensional pie shape.
back to the top

Example: Determining Chart Type of Graph

The following example determines if the chart type of the graph in the earlier example is a 2-Dimensional Bar type:
  1. Open any module in Design view. On the Tools menu, click References, select Microsoft Graph 9.0 Object Library, and then click OK.
  2. Using the form created in the first example, change the code of the command button to the following:
    Dim GraphObj As Object
    Set GraphObj = Me![MyGraph].Object.Application.Chart
    If GraphObj.Type = xLBar Then 'xLBar equals 2
       Msgbox "The graph is a 2-D Bar chart"
    Else
       Msgbox "The graph is NOT a 2-D Bar chart"
    End If
    					
  3. Switch the form to Form view. When prompted for a beginning and ending date, type 1/1/97 and 1/1/98. Click the command button.

    Note the message box that states the graph is not a 2-Dimensional Bar chart.
back to the top


REFERENCES

For more information about 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 different chart types, click Microsoft Chart Help on the Help menu, type chart types in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more examples of Automation between Microsoft Access and Microsoft Graph, see the Office 2000 Automation Help file, Auto2000.exe. The Auto2000.exe file contains the Microsoft Office 2000 Automation Help file created by Microsoft Technical Support. This Help file contains Automation theory and multiple examples on automating all the Microsoft Office 2000 products (Microsoft Access, Microsoft Excel, Microsoft Word, Microsoft PowerPoint, and Microsoft Outlook) as well as Microsoft Graph, DAO/ODBCDirect, Microsoft Binder, OLE Messaging, and the Office Assistant. back to the top






Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbHOWTOmaster kbinterop KB210021 kbAudDeveloper