Gerald:
Forget about the interface for a moment and examine the table structures.
Getting these right is the first essential. Lets take things one by one:
If each component can only be in one product the relationship here is
one-to-many from Products to Components, so there should be no foreign key in
Products referencing components, but a foreign key ProductID column in the
Components table. If, however, each component can be in more than one
product then the relationship is many-to-many so you need another table to
model the relationship, ProductComponents say, with foreign keys ProductID
and ComponentID.
The same principles apply: if each ingredient can only be in one component
the relationship here is one-to-many from Components to Ingredients, so there
should be a foreign key ComponentID column in the Ingredients table. If,
however, each component can be in more than one product then the relationship
is many-to-many so you need another table to model the relationship,
ComponentIngredients say, with foreign keys ComponentID and IngredientID.
This is a clear cut many-to-many relationship between Ingredients and
Suppliers, so a table, IngredientSuppliers say, is needed to model it, having
IngredientID and ProductID foreign keys columns.
So the first thing you need to do is decide on what type of relationships
there are between Products and Components, and between Components and
Ingredients. Then you can create the tables appropriately on the basis of
the answers to these questions, and design an interface which reflects the
'logical model'.
You might find the above easier to follow if you draw the structure out
diagrammatically as an 'entity relationship diagram', with a box for each
table and lines connecting them representing the relationships. The
many-to-many relationships should not be shown directly but resolved as two
one-to-many relationships, e.g.
Products----<ProductComponents>----Components
where the < and > characters represent the 'many' side of the relationship.
Now I'm going to throw another spanner in the works. The above comments are
on the basis of your description, i.e. that each product is made up of one
level of 'components' each of which is made up of a number of atomic
ingredients. However, another possible scenario is that a 'component' might
be made up of other components and so on, with only the bottom level
components being made up of atomic ingredients, i.e. the components are
assemblies which are made up of sub-assemblies, which in turn are made up of
other sub-assemblies and so on until the bottom level of the atomic parts
making up the assemblies is reached. This would require a very different
logical model. The usual model for this is to have a table Parts which
includes all atomic parts and all assemblies in the one column. A second
table PartStructure say is an 'adjacency list' having columns MajorPart and
MinorPart say, both referencing the key of Parts.
With the above model to produce a 'bill of materials' or 'parts explosion'
for a product or assembly requires recursive querying with a variable number
of calls of the query. There are a number of theoretical approaches to this,
but none which can be directly reproduced in a real query. It is possible to
simulate it in Access and I published a means of doing so in a magazine
article some years ago. The demo file is no longer on their site, however,
but I'd be happy to mail it to you if you wish.
Ken Sheridan
Stafford, England