The file CHARTS.MDB contains an attached table, a query, two forms,
a report and a module.

The Table:
================
When the database opens it will try to verify that the Orders
table is attached to C:\ACCESS\SAMPAPPS\NWIND.MDB.  If it cannot
you will receive an alert dialog indicating that it couldn't
find the database.  All you need to do is refresh the attachment
to the Northwind Sample database provided with Access.

Choose Add-Ins from the File Menu, and then select the Attachment
Manager Sub-Menu.  Check the box next to C:\ACCESS\SAMPAPPS\NWIND.MDB.
Then hit the OK button.  The attachment manager will prompt you to 
find your copy of NWIND.MDB, find it and hit OK.

The Forms:
================
The Orders table is used by the forms 'Chart with Scrollbars'
and 'Chart with Values' to create the chart: 'Employees Sales
Freight Charges'.

These forms are examples of how to use OLE Automation to modify
the Minimum and Maximum values of the Value Axis on a chart.

The 'Chart with Scrollbars' requires the Scrollbar Custom Control
that ships with the Access 2.0 ADT.  If you are not going to be
shipping an App that uses the Scrollbar in this manner, it doesn't
matter whether I demonstrate it to you or not, and I didn't want
to complicate the issue by trying to ship the Scrollbar Control 
just for a Demo.

Please post any questions regarding the use of the Scrollbar Custom
Control in 'Section 19 - OLE Controls' of the MSACCESS Forum.


The Reports:
================
'Employee Freight by Month 1991' is a report that is based on the query 
'Employee Freight 1991', which is simply a select query used to limit 
the Orders Table to one year's worth of data and format the data the
way I like it.  

To show that you could modify the pieces of a graph in a report on
the Format event, I set the Maximum value of the Value axis to two
times the maximum value in the data rounded up to the nearest 100.

So if the maximum value is 340 I round up to 400 and multiply by
two, which means the value Axis will be 800.

There are 3 functions behind the report that are used to modify the 
settings in the graph.

The first two calculate the maximum value in the graph by setting 
the field MaxOfFreight to zero during the Employee ID On Format event.
Then checking each SumOfFreight in the detail section to see if
it is greater than the last.  At this point it also notes the month
that has the highest value.  This is only for the report and is not
used in the graph.

Sub GroupHeader5_Format (Cancel As Integer, FormatCount As Integer)
    MaxOfFreight = 0
End Sub

Sub Detail1_Format (Cancel As Integer, FormatCount As Integer)
    If SumOfFreight > MaxOfFreight Then
        MaxOfFreight = SumOfFreight
        BestMonth = [Month]
    End If
End Sub


When the Detail Section is finished the Employee Id On Format event
sets the value on EmployeeChart with the following code":

Sub GroupFooter6_Format (Cancel As Integer, FormatCount As Integer)
    EmployeeChart.Object.Axes(XlValue).MaximumScale = 200 * (Int([MaxOfFreight] / 100) + 1)
    EmployeeChart.Object.Axes(XlValue).MinimumScale = 0
End Sub


I multiplied the value by 200 in order to show the effect.  The real
trick is coming up with the value the way you would like it to be.

Also, remember to set the MinimumScale.  If you don't you can sometimes
end up with negative minimum values do to the value of the Major unit.
You can also modify this value, if you want it to be a fixed amount 
all the time.

The Module:
================
The module is used to store some of the Excel constants that graph uses.
Unfortunately they are not documented in the Graph Help File yet, so 
you have to get them from Excel for now.

More Information:
================
You can find more information on controlling Graph via OLE Automation
in the file VBA_GRP.HLP included in this package.  This file describes 
the Objects, Methods and Properties of MS Graph 5.0.

You are free to modify and distribute these examples as you wish.
There are no guarantees that this will solve the worlds problems...

But I like to think I'm tryin'!

Gary Yukish
Microsoft PSS - Access
[72662,1616]
