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.
- Open the sample database Northwind.mdb.
- Create a new form as follows:
- Use the Chart Wizard to create a new form based on the Orders table.
- 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.
- In the "What type of chart would you like" dialog box, click Column
Chart, and then click Next.
- 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.
- 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.
- When the form opens in Design view, set the Name property of the Graph
object to GraphOrders.
- 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]
- 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
- Save the form as frmOLEGraph and switch it to Form view.
- 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.
- Click the Change Graph button. Note that the Y-axis ranges from 1 to
100 in increments of 20.5.