Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Automate Changes to Properties of a Graph Axis

View products that this article applies to.

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

↑ Back to the top


This article shows you how to use code to change the properties of a graph on a form. The example shows you how to change the Minimum and Maximum Scale, and the Minor and Major Unit properties of the Y-axis on a Microsoft Graph object embedded in a form.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

↑ Back to the top

More information

In the following example, you create a form with a graph, four text boxes, and a command button. You type the values for Minimum Scale, Maximum Scale, Minor Unit, and Major Unit in the text boxes, and then click the button to see the changes in the graph.
  1. Open the sample database Northwind.mdb.
  2. Create a new form as follows:
    1. Use the Chart Wizard to create a new form based on the Orders table.
    2. In the "Which fields contain the data you want for the chart?" dialog box, add OrderID and EmployeeID to the Fields For Chart box, and then click Next.
    3. In the "What type of chart would you like" dialog box, click Column Chart, and then click Next.
    4. In the "How do you want to lay out the data in your chart?" dialog box, drag OrderID to Data (at the upper-left of the graph). Drag EmployeeID to Axis (at the bottom of the graph). Leave Series blank, and then click Next.
    5. In the "What title would you like for your chart" dialog box, type Orders by Employee, click "Modify the design of the form or the chart," and then click Finish.
  3. When the form opens in Design view, set the Name property of the Graph object to GraphOrders.
  4. Add the following controls to the detail section of the form:
       Text Box:
          Name: MinScale
       Text Box:
          Name: MaxScale
       Text Box:
          Name: MinorUnit
       Text Box:
          Name: MajorUnit
       Command Button:
          Name: ChangeGraph
          Caption: Change Graph
          OnClick: [Event Procedure]
  5. Click the Build button next to the OnClick property of the command button and type the following code:
    Private Sub ChangeGraph_Click()
    Me![GraphOrders].Axes(2).minimumscale= Me![MinScale]
    Me![GraphOrders].Axes(2).maximumscale= Me![MaxScale]
    Me![GraphOrders].Axes(2).minorunit= Me![MinorUnit]
    Me![GraphOrders].Axes(2).majorunit= Me![MajorUnit]
    End Sub
  6. Save the form as frmOLEGraph and switch it to Form view.
  7. Note the appearance of the graph. Type 1 in the MinScale box, 100 in the MaxScale box, 5 in the MinorUnit box, and 20.5 in the MajorUnit box.
  8. Click the Change Graph button. Note that the Y-axis ranges from 1 to 100 in increments of 20.5.

↑ Back to the top


For more information about changing Graph objects, click Microsoft Access Help on the Help menu, type graph in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top

Keywords: KB198468, kbprogramming, kbhowto

↑ Back to the top

Article Info
Article ID : 198468
Revision : 5
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 344