HandsOn Writing the Form AfterFinal Render Event Procedure

1. In the Visual Basic Editor window, double-click Form_Sales Analysis Subform 2.

2. The Code window shows the procedures created in the previous hands-on exercises for this chapter. Enter the following Form_AfterFinalRender event procedure below the last procedure code.

Private Sub Form_AfterFinalRender(ByVal drawObject As Object) Dim oChart As Object Dim s As Object Dim p As Object Dim strText As String Dim num As Integer

Set oChart = Me.ChartSpace.Charts(0)

For Each s In oChart.SeriesCollection For Each p In s.Points num = num + 1 Debug.Print num


Next strText = "This chart contains " & num & " data points."

With drawObject.Font .Size = 9 .Color = "blue" .Italic = True End With drawObject.DrawText strText, 200, 20 End Sub

3. Switch to the Sales Analysis Subform 2 form and choose View | PivotChart View. When the form opens you should see the PivotChart formatted as shown in Figure 24-4.

Part IV

Figure 24-4: After all the elements of the PivotChart have been drawn on the screen, the procedure in Hands-On 24-26 calculates the total number of data points in the chart and places this information in the text message in the PivotChart view.
0 0

Post a comment