Changing the source of a graph

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a report in which there is a graph (using microsoft graph 2000). I
would like to change the source of the graph every time the report is being
opened (using an sql query that will be given to it).
I tried writing in the report_load sub:
chart.rowSource = ...
but the chart doesn't seem to have a rowSource property.
Anybody knows how it can be done?

thank you
 
Changing the row source of a graph won't change the data displayed as you've
found. The only way to change the data displayed is to load the data into
the data sheet object in graph using a recordset. Here's an example, which
you can run from the On Print event of the section that the graph object is
in; of course you can pull the recordset as a global variable or pass it to
the report as a property:
--
Steve Arbaugh
ACG Soft
http://ourworld.compuserve.com/homepages/attac-cg

---------------------

Dim objGraph As Object, objDS As Object, rsData As Recordset
Dim intRowMax%, intColMax%, arrData As Variant
Dim i%, j%
Set objGraph = Me!Graph1.Object
Set objDS = objGraph.Application.DataSheet
Set rsData = CurrentDb.OpenRecordset("Select * from tblXYZ")
arrData = rsData.GetRows(200)
intRowMax = UBound(arrData, 1)
intColMax = UBound(arrData, 2)
'data sheet cells are in row, column, starting at 1,1 with the headers
'array is in column, row starting at 0, where row 0 is the first row of
data; no headers
'Add the column heads
For i = 0 To rsData.Fields.Count - 1
objDS.cells(1, i + 1) = rsData.Fields(i).Name
Next i
'Add the data
For i = 0 To intRowMax
For j = 0 To intColMax
objDS.cells(i + 2, j + 1) = arrData(j, i)
Next j
Next i
DoEvents
Me.Graph1.Object.Application.Update
 
Back
Top