Access VBA Macro Programming

(Joao Candeias) #1

The preceding code sets the label on each slice to display both the value and the category
name, which is the name declared on the legend of the chart.
You can also change the color of the pie chart segments by using:


ch.SeriesCollection( 1 ).Points( 1 ).Interior.Color = QBColor( 12 )


I once had to write some Access reports for foreign exchange trading. One of these had a
page for each customer and a pie chart detailing the split in currencies traded. Some
customers traded in a whole range of currencies, whereas others only traded in one or two.
The problem with using the pie chart was that the segment colors were not consistent for
each customer due to the number of currencies being traded.
The customer required each currency to have a specific color segment regardless of which
customer it was. This was accomplished by writing code to change the segment color using
predefined parameters.


Exporting a Chart as a Picture File


A chart can be easily exported as a GIF, JPEG, or PNG file using the following code. This
example assumes you have a chart already defined on a report.


Sub OutputChart()
Dim ch As Graph.Chart
Set ch = Me.Graph0.Object


ExportFile = Access.CodeProject.Path & "\" MyChart.gif"

ch.Export Filename:=ExportFile, FilterName:="GIF"
End Sub


Chapter 18: Charts and Graphs 237

Free download pdf