Microsoft KB Archive/304171

= ACC2002: How to Programmatically Rotate a Chart in PivotChart View =

Article ID: 304171

Article Last Modified on 6/23/2005

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



This article was previously published under Q304171



Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).



SUMMARY
This article describes how to programmatically rotate a chart in PivotChart view in Microsoft Access.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.



MORE INFORMATION
 Start Microsoft Access, and then open the sample database Northwind.mdb. Open a new, blank form in Design view. In the toolbox, make sure that the Control Wizards button is enabled, and then add a subform/subreport control to the form. The Subform Wizard will start. On the first page of the Subform Wizard, click Use existing Tables and Queries, and then click Next. On the second page of the wizard, click the arrow in the Tables/Queries box, and then click the Category Sales for 1997 query. Add the CategorySales and CategoryName fields to the Selected Fields box, and then click Next.</li> On the last page of the wizard, name the subform MyChart, and then click Finish.</li> On the View menu, click Properties.</li> Click the arrow in the box at the top of the property sheet, and then click Form.</li> Click the Format tab, and then set the DefaultView property to Single Form.</li> Close the property sheet.</li> Make the subform a little bigger so that you can work with it better.</li> Double-click the form footer section of the subform to open the property sheet for the form footer section. For the box at the top of the property sheet, make sure that Form is selected.</li> On the Format tab, set the DefaultView property to Pivot Chart, and then close the property sheet.</li> Save the form, and then switch the form to Form View.</li> If the field list is not visible, right-click the chart and then click Field List.</li> Drag the CategoryName field from the field list to the box on the chart that reads Drop Category Fields Here.</li> Drag the CategorySales field from the field list to the box on the chart that reads Drop Data Fields Here.</li> Save the form, and then switch the form back to Design view.</li> Add a command button to the form with the following properties:

Caption: Rotate Chart

OnClick: =RotateChart

</li> Click the form, and then, on the View menu, click Code to open the module of the form.</li> On the Tools menu, click References, and then add a reference to the Microsoft Office XP Web Components. If this reference is not listed, click the Browse button to browse to the following file, and then click OK:

C:\Program Files\Common Files\Microsoft Shared\WebComponents\10\OWC10.dll.

</li> <li>Close the References dialog box.</li> <li> Add the following code to the module of the form: Function RotateChart

Dim objPivotChart As OWC10.ChChart Dim objChartSpace As OWC10.ChartSpace Dim frmChart As Access.Form Dim OldRotation As Integer Dim NewRotation As Integer Dim TopDegree As Integer Set frmChart = Me.Controls(&quot;MyChart&quot;).Form Set objChartSpace = frmChart.ChartSpace Set objPivotChart = objChartSpace.Charts.Item(0) 'Set type of chart to a 3D Column. objPivotChart.Type = chChartTypeColumn3D ' Determine the initial rotation setting. OldRotation = objPivotChart.Rotation ' Determine the number of degrees you have to count up to. TopDegree = OldRotation + 360

'The following code will rotate the chart 360 degrees. For NewRotation = OldRotation To TopDegree Step 12 'Determine if the Rotation must be adjusted to fit under 360 'degrees. If NewRotation > 360 Then objPivotChart.Rotation = NewRotation - 360 Else objPivotChart.Rotation = NewRotation End If     DoEvents DoCmd.RepaintObject Next End Function </li> <li>Compile and save the code. Then, close the Visual Basic Editor.</li> <li>Switch the form to Form view, and then click the command button. Note that the chart rotates 360 degrees.</li></ol>

Additional query words: inf

Keywords: kbhowto KB304171

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.