Finally, we get to the interesting bit of the VBA code to create a report, add a chart to it,
and manipulate it with VBA. Insert a new module by clicking Insert | Module in the VBE
window and adding the following code:
Sub CreateGraphOnReport()
Dim rep As Report
Dim ctl As control
Dim ch As Graph.Chart
Dim RepName As String
DoCmd.OpenReport "rptTemplate", acDesign, , , , acHidden
Set rep = CreateReport()
Set ctl = CreateReportControl(rep.Name, acObjectFrame, acDetail)
ctl.OleData = Reports!rptTemplate!Graph0.OleData
DoCmd.Restore
Chapter 18: Charts and Graphs 233
Figure 18-2 Population of the tblChart Table