To create a chart that displays data selected by two combo boxes, follow these steps:
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.
- Start Microsoft Access and open the sample database Northwind.mdb.
- In the Database window, click Queries, and then click New to create a new query in Design view.
- In the Show Table dialog box, add the following tables, and then click Close.
Orders
Order Details
Products
Categories
- On the View menu, click Totals.
- Add the following fields to the query grid:
Field: Freight
Table: Orders
Total: Sum
Field: ProductName
Table: Products
Total: Group By
Field: CategoryName
Table: Categories
Total: Group By
Field: Year: CStr(Nz(Year([OrderDate])))
Total: Group By
- Save the query as qryGraph and close it.
- In the Database window, click Forms, and then click New. In the New Form dialog box, click Chart Wizard, and then select qryGraph as the query which the object's data comes from. Click OK.
- Move the SumofFreight, ProductName, and CategoryName fields from the Available Fields box to the Fields for Chart box, and then click Next.
- In the next wizard dialog box, select the Column Chart type, and then click Next.
- In the next wizard dialog box, drag CategoryName to the Axis list (bottom of graph), and then drag ProductName to the Series list (right side of graph). Be sure that they replace the items that are already displayed in the Axis list and the Series list. Click Next.
- In the next wizard dialog box, type
Freight Dollars by Category as the title of your chart, and then click Finish. The form opens in Form view.
- On the View menu, click Design View.
- On the View menu, click Form Header/Footer.
- Add two combo box controls to the Form Header section, and then assign the following properties to each combo box:
Combo Box 1
Name: SelectCat
Row Source Type: Table/Query
Row Source: Categories
Column Count: 2
Column Width: 0";1"
Bound Column: 2
Combo Box 2
Name: SelectYear
Row Source Type: Value List
Row Source: 1996;1997;1998;1999
- Click the graph, and modify the following properties of the unbound
object frame:
Unbound Object Frame
Name: FreightGraph
Size Mode: Zoom
Link Child Fields: CategoryName;Year
Link Master Fields: SelectCat;SelectYear
Width: 6.5"
Height: 3.25"
- On the View menu, click Form View. Click different categories and years in each of the two combo boxes on the form.
Note that the contents of the graph change. If you select 1999 as the year, the graph is blank because there is no data for that year.