Hi Glenda. You *definately* do not want a field for each part. To solve this
problem, you will need to set up a good relational database, and then design
a query with an outer join. This answer is rather long, but it will solve
not only this problem but lots of others you have not come across yet. I
hope you stick with it and get it solved.
Presumably these are parts that are used or sold in some kind of
transactions. I'll assume you are using parts as part of services on
vehicles or something. You will need at least these tables:
Part table (one record for each part.) Fields:
PartID AutoNumber primary key
PartNum Text the part number.
PartName Text description of the part.
...
Service table (one record for each service):
ServiceID Autonumber primary key
ServiceDate Date/Time Date this service was completed.
...
ServiceDetail table (one record for each part used in a service):
ServiceDetailID AutoNumber primary key
ServiceID Number. Which service this part was used in.
PartID Number. Which part was used in this service.
Quantity Number. How many of this part used in this
service.
In the Relationships window (Tools menu), you will create relationships from
ServiceDetail table back to the other 2.
The interface will be a main form for the Service, with a subform for the
parts used in the service (one per row.)
Once you have those tables in place, you can create the query:
1. Create a query, and add the Service and ServiceDetail tables.
2. Depress the Total icon on the toolbar.
Access adds a Total row to the grid.
3. Drag the ServiceDate field into the grid.
Accept Group By in the Total row under this field.
4. Drag the PartID field into the grid.
Accept Group By under this field.
5. Drag the Quantity field into the grid.
In the Total row under this field, choose: Sum
6. Save the query with the name (say) qryDailyPartCount. Close.
7. Create another query, using the Part table and qryDailyPartCount as
source tables.
8. In the upper pane of query design, you should see a line joining PartID
in both tables. If not, drag PartID from one table onto the other.
9. Double-click the line joining the 2 tables.
Access pops up a dialog offering 3 choices.
Choose the one that says:
All records from Part, and any matches from qryDailyPartCount.
10. Drag these fields into the output grid for your query:
- PartID from the Part table;
- SumOfQuantity from qryDailyPartCount;
- ServiceDate from qryDailyPartCount.
11. In the Criteria row under the service date, enter the date range you
want, plus the Null condition, e.g.:
IsNull Or Between #1/1/2006# And #1/31/2006#
At step 9, you created an outer join. That, in combination with the
inclusion of nulls at step 11 ensure all parts show in the results.
More info about outer joins and the nulls issue in this article:
The Query Lost My Records!
at:
http://allenbrowne.com/casu-02.html