Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Change the Order of Columns in a Chart


View products that this article applies to.

This article was previously published under Q208651
Advanced: Requires expert coding, interoperability, and multiuser skills.

↑ Back to the top


Summary

By default, a chart sorts the X-axis fields in alphabetical or numeric order. This article describes two methods that you can use to sort the X-axis fields in a different order.

↑ Back to the top


More information

There are two methods you can use to change the ordering of fields in a chart. The first way is to add an ORDER BY clause to the SQL statement in the chart's RowSource property. The second way is to create a query that orders the fields the way that you want them, and then to use the query for the chart's RowSource property.

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

How to Create a Sample Chart

To create a chart, follow these steps:
  1. Open the sample database Northwind.mdb.
  2. Create a new, blank form not based on any table or query.
  3. On the Insert menu, click Chart, and then click in the detail section of the form where you want the chart to appear.
  4. In the Chart Wizard dialog box, select the Sales By Category query as the data source for the chart, and then click Next.
  5. Add the CategoryName and ProductSales fields to the Fields For Chart box, and then click Finish.
  6. View the form in Form view. Note that the CategoryName records are listed in alphabetical order.

How to Change the Chart's Sorting Order

Method 1

The following example demonstrates how to add an ORDER BY clause to the SQL statement in a chart's RowSource property:
  1. Open the form that you created in the section "How to Create a Sample Chart" in Design view.
  2. Select the chart.
  3. If the property sheet is not displayed, on the View menu, click Properties.
  4. Select the RowSource property of the chart, and then press SHIFT+F2 to zoom in on the window. Note that the RowSource property's SELECT statement reads as follows:
    SELECT [CategoryName],Sum([ProductSales]) AS [SumOfProductSales] FROM [Sales by Category] GROUP BY [CategoryName];
  5. Type Order By SUM([ProductSales]) desc before the semicolon at the end of the SQL statement so that the SQL statement reads as follows:
    SELECT [CategoryName],Sum([ProductSales]) AS SumOfProductSales] FROM [Sales by Category] GROUP BY [CategoryName] Order By SUM([ProductSales]) desc;
  6. Click OK.
  7. View the form in Form view. Note that the CategoryName records are now listed in descending order of sales.

Method 2

The following example describes how to create and use a query for the chart's RowSource property:
  1. Re-create the form with a chart that you created in the section "How to Create a Sample Chart."
  2. Select the chart.
  3. If the property sheet is not displayed, on the View menu, click Properties.
  4. Using the right mouse button, click the RowSource property, and then click Build.
  5. In the SQL Statement: Query Builder window, set the sort order for the ProductSales field to Descending.
  6. Close the SQL Statement: Query Builder window and save the changes.
  7. View the form in Form view. Note that the CategoryName records are listed in descending order of sales.

↑ Back to the top


References

For more information about ordering fields, click Microsoft Access Help on the Help menu, type ORDER BY clause in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

↑ Back to the top


Keywords: KB208651, kbhowto

↑ Back to the top

Article Info
Article ID : 208651
Revision : 2
Created on : 6/29/2004
Published on : 6/29/2004
Exists online : False
Views : 272