Taking the tables I suggested as the starting point you can eliminate the
manufacturers table. So the makes table is:
Makes
----Make (primary key)
You can add other columns as necessary to represent attributes of each make.
Tables represent entity types. Engines, transmissions, powertrains are all
entity types so you'd have a table for each of these:
Engines
----Engine (primary key)
Transmissions
----Transmission (primary key)
Powertrains
----Powertrain (primary key)
Again you can add other columns as necessary to represent attributes of each
entity type.
Models is also an entity type, but is slightly different as it will
reference makes:
Models
----Model (primary key)
----Make
You'll see that in each of these I've used 'natural keys' such as Make,
Model, Engine etc rather than numeric 'surrogate keys' such as MakeID,
ModelID, EngineID. This assumes than the values of each are distinct e.g.
two makes cannot have models of the same name. If they can then either a
numeric surrogate key would be necessary, or the primary key would be a
composite one of Make and Model. Natural keys will make things easier,
though, as you'll see below.
I've ignored Year for the moment as you say you have that integral with Make.
All of the above tables stand independent of each other apart from Makes and
Models (which references Makes), but the others are of course related in a
4-way many-to-many relationship. This relationship is modelled by another
table, which I'll call Vehicles, like so:
Vehicles
----Model
----Engine
----Powertrain
----Transmission
----TowingCapacity
The primary key of this table is a composite one of Model, Engine,
Powertrain and Transmission.
Although this table models a relationship type it also models an entity type
because relationship types are really just a special kind of entity type. So
again you can add other columns as necessary to represent attributes of this
entity type (Towingcapacity is such a 'non-key' attribute. Relationships
should be created between this table and Models, Engines, Powertrains, and
Transmissions. In the relationships referential integrity and cascade
updates should be enforced.
As for a form to search for vehicles I'd suggest you use a form, frmVehicles
say, in continuous form view bound to a query which references a series of
combo boxes from which you can select model, engine etc.
Put the unbound 'search' combo boxes in the form header. Each will list the
values from one table, so you'd have combo boxes cboModel, cboEngine,
cboTransmission and cboPowertrain. As an example the RowSource property of
cboEngine would be:
SELECT Engine FROM Engines ORDER BY Model;
The others would have similar RowSource properties drawing on the relevant
table in each case. The cboModel control would differ, however, by having a
RowSource of:
SELECT Model, Make FROM Models ORDER BY Make, Model;
and its other properties would be set up like so:
BoundColum: 1
ColumnCount: 2
ColumnWidths: 3cm;3cm
ListWidth: 6cm
If your units of measurement are imperial rather than metric Access will
automatically convert the above. Experiment with the ColumnWidths to get the
best fit. The ListWidth should be the sum of the ColumnWidths. To show the
make fro the selected model add a text box, txtMake, to the form header with
a ControlSource property of:
=[cboModel].[Column](1)
The Column property is zero-based, so Column(1) is the second column.
The query on which the form is based would be:
SELECT *
FROM Vehicles
WHERE (Model = Forms!frmVehicles!cboModel
OR Forms!frmVehicles!cboModel IS NULL)
AND (Engine = Forms!frmVehicles!cboEngine
OR Forms!frmVehicles!cboEngine IS NULL)
AND (Powertrain = Forms!frmVehicles!Powertrain
OR Forms!frmVehicles!Powertrain IS NULL)
AND (Transmission = Forms!frmVehicles!cboTransmission
OR Forms!frmVehicles!cboTransmission IS NULL)
ORDER BY Model;
In The AfterUpdate event procedures of the cboModel, cboEngine,
cboTransmission and cboPowertrain controls you'd requery the form with:
Me.Requery
As an item is selected from one of the combo boxes the form will be
requeried to show only those vehicles which match the selection, so as items
are progressively selected from the combo boxes the vehicles listed will be
narrowed down progressively on the basis of the combination of items selected
in the combo boxes.
To compute the amount of a commodity a trailer can carry add another combo
box, cboTrailer to the header with a RowSource along these lines:
SELECT Trailer, TrailerWeight FROM Trailers ORDER BY Trailer;
Set its other properties up exactly like cboModel.
To select a commodity add another combo box, cboCommodity with a RowSourece
along these lines:
SELECT Commodity, CommodityWeight FROM Commodities ORDER BY Commodity;
Again set its other properties up exactly like cboModel.
To show the amount of the selected commodity which can be carried in the
selected trailer by each vehicle add an unbound control to the form's detail
section with a ControlSource property of:
=([TowingCapacity]-[cboTrailer].[Column](1))/[cboCommodity].[Column](2)
I haven't been able to test the above of course, but I think I've got the
essentials right.
Ken Sheridan
Stafford, England