Access VBA Macro Programming

(Joao Candeias) #1

The report is saved and renamed to rptMyGraph and then opened in Design mode. The
subsequent code will not work if the report is not in Design mode.
The Chart object created at the start of the code can now be set to the OLEObject on the
report. You now have access to all the normal properties and methods you would expect for a
chart object, such as changing the type of chart and changing the title.
Note that theHasTitleproperty must be set to True before defining the text for the title of
the chart. Also, note that some of the properties must be set for the OLE Object (such as Top
and Left) and not for the Chart itself.
Run this code, and your chart should look like Figure 18-3.
Although the code has created the chart on a report, this code can also be used on a form.
Also, if you already have a chart control (added using the Chart Wizard) on your report/form
and simply want to manipulate it, you can use the following code to create a chart object
in VBA:


Dim ch As Graph.Chart
Set ch = Me.Graph0.Object


Chapter 18: Charts and Graphs 235


Figure 18-3 A pie chart on a report created using the VBA example

Free download pdf