Microsoft Access VBA Macro Programming

(Tina Sui) #1
Save the table astblCurrency. On your blank form, drag a chart object onto the form.
Make your currency table the row source for the chart. Select a pie chart as the chart type.
Right-click the chart and select Chart Object and then Edit on the pop-up menu. Right-click
the chart object and select Chart Options on the pop-up menu.
Click the Data Labels tab in the pop-up window and check the box for Category Name in
the Label Contains section. Your pie chart should now show the currency indicator on the
appropriate segment.
You will need to add a reference into the Chart Object library. In the VBE window, use
Tools | References from the menu and select Microsoft Graph 12.0 Object Library. Mark the
check box and click OK.
Next, add the following code to your form (this goes on the Form Activate event):

Private Sub Form_Activate()

Dim ch As Graph.Chart, Temp As String, PointCount As Integer

Set ch = Me.Graph0.Object

PointCount = ch.SeriesCollection( 1 ).Points.Count
For n = 1 To PointCount
Select Case ch.SeriesCollection( 1 ).Points(n).DataLabel.Text
Case "USD"
ch.SeriesCollection( 1 ).Points(n).Interior.Color = QBColor( 9 )
Case "GBP"
ch.SeriesCollection( 1 ).Points(n).Interior.Color = QBColor( 10 )
Case "EUR"
ch.SeriesCollection( 1 ).Points(n).Interior.Color = QBColor( 11 )
Case "AUD"
ch.SeriesCollection( 1 ).Points(n).Interior.Color = QBColor( 12 )
Case "HKD"
ch.SeriesCollection( 1 ).Points(n).Interior.Color = QBColor( 13 )
End Select

Next n
Set ch = Nothing
End Sub

322 Microsoft Access 2010 VBA Macro Programming


Currency Value
USD 1627.89
GBP 4533.21
EUR 3445.67
AUD 3289.45
HKD 3345.56
Table 33-1 Currency Table Values
Free download pdf