ACC: How to Change the Order of Columns in a Chart (1.x/2.0)
ID: Q109315
|
The information in this article applies to:
-
Microsoft Access versions 1.0, 1.1, 2.0
SUMMARY
Advanced: Requires expert coding, interoperability, and multiuser skills.
By default, a graph sorts the X-axis fields in alphabetical or numeric
order. This article describes two ways to sort the X-axis fields in a
different order.
MORE INFORMATION
There are two ways to change the ordering of fields in a graph. The first
way is to add an Order By clause to the SQL statement in the graph's
RowSource property. The second way is to create a query that orders the
fields the way you want them, and then use the query for the graph's
RowSource property.
How to Create a Sample Graph
For Microsoft Access version 2.0:
- Open the sample database NWIND.MDB.
- Create a new, blank form, and then add a graph object to the form.
- In the GraphWizard dialog box, select the Sales By Category query as
the data source for the graph.
- Select the Category Name field in the Available Fields box and then
choose the ">" button. Then select the Product Sales field and choose
the ">" button. Click Next three times, and then click Finish.
- View the form in Form view. Note that the Category Name records are
listed in alphabetical order.
For Microsoft Access version 1.x:
- Open the sample database NWIND.MDB.
- Create a new, blank form, and then add a graph object to the form.
- In the Graph Wizard dialog box, select the Sales By Category query as
the data source for the graph. Then, click the Bar Chart button, and
then choose Next.
- Select the Category Name field in the Available Fields box and then
choose the ">" button. Then select the Product Sales field and choose
the ">" button. Choose Next.
- Choose Design.
- View the form in Form view. Note that the Category Name records are
listed in alphabetical order.
How to Change the Graph's Sorting Order
Method 1:
The following example demonstrates how to add an Order By clause to the SQL
statement in a graph's RowSource property:
- View the form in Design view.
- Select the Graph.
- From the View menu, choose Properties.
- Select the RowSource property, and then press SHIFT+F2 to zoom the
window. The RowSource property looks like:
SELECT DISTINCTROW [Category Name] AS [Sales by Category],
SUM([Sales by Category].[Product Sales]) AS [Product Sales]
FROM [Sales by Category]
GROUP BY [Category Name];
- Type Order By SUM([Sales by Category].[Product Sales]) desc
before the semicolon at the end of the SQL statement. The SQL statement should look like:
SELECT DISTINCTROW [Category Name] AS [Sales by Category],
SUM([Sales by Category].[Product Sales]) AS [Product Sales]
FROM [Sales by Category]
GROUP BY [Category Name]
Order By SUM([Sales by Category].[Product Sales]) desc;
- Choose OK.
- View the form in Form view. Note that the Category Name records are
now listed in descending order of sales.
Method 2:
The following example describes how to create and use a query for the
graph's RowSource property:
For Microsoft Access version 2.0:
- Create a form with a graph using the above steps.
- View the form in Design view.
- With your secondary mouse button, click the graph object, and then
choose Properties.
- With your secondary mouse button, click the Row Source property and
then choose Build.
- For the Product Sales field, change the sort order to Descending.
- Close the Query window and save the changes.
- Switch to Form view.
For Microsoft Access version 1.x:
- Create a form with a graph using the above steps.
- Make a copy of the Sales By Category query. Call the copy Sales By
Category 2.
- Open the Sales By Category 2 query in Design view. Create the following
fields in the query:
Field: Sales by Category:Category Name
Total: Group By
Sort: <leave blank>
Field: Product Sales
Total: Sum
Sort: Desc
Note that the first field is named "Sales by Category:Category Name"
because the name of the first field becomes the graph's title.
- Remove the Product Name field.
- Save the query.
- View the form in Design view. Replace the SQL text in the graph's
RowSource property with the Sales By Category 2 query.
- View the form in Form view.
The columns will be in descending order.
REFERENCES
For more information about ordering fields, search for "order by," and then
"ORDER BY Clause (SQL)" using the Microsoft Access Help menu.
For more information about this topic in Microsoft Access 95 and 97, please
see the following article in the Microsoft Knowledge Base:
Q141235 ACC: How to Change the Order of Columns in a Chart (95/97)
Additional query words:
queries msgraph
Keywords : kbtool IntpGrph
Version : 1.0 1.1 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 30, 1999