Creating a Graph/Chart on a Report in VBA


Question

I just want to create a graph on a report within a module (using VBA) at run-time. Any suggestions on how to carry out this task or if anyone knows where I can get my hands on some good source code relating to this then that would be great.

Answer


John,

Here is the trick based on wztool80.wztool_mod.cw_ErrCreateChart function:

Dim rpt As Access.Report
Dim ctlObjFrame As Access.ObjectFrame
Dim cw_rsTemplates As DAO.Recordset

Set rpt = CreateReport
Set ctlObjFrame = CreateReportControl(rpt.Name, _
      acObjectFrame, , "", "", 100, 100)
Set cw_rsTemplates = CodeDb().OpenRecordset( _
      "cw_tblChartTemplates", dbOpenDynaset)
cw_rsTemplates.MoveFirst
' Set OleData property to template graph from OLE field
ctlObjFrame.OleData = cw_rsTemplates!ChartObject
DoCmd.Restore

Get wztool80 sources and dig into them...

HTH,
Shamil


Copyright 1999-2008 by Shamil Salakhetdinov. All rights reserved.