Stacie:
If you use a combo box, which sounds a more appropriate solution here, set
the control's LimitToList property to True (Yes) as Scott describes. With a
list box the user can't enter rows manually, so the question doesn't arise.
However, do not use a value list as the RowSourceType property unless the
list is one of terms fixed in the external world, e.g. days of the week,
months of the year etc. If you use a value list to compile a list of values
of your own making you are storing data other than as values at row positions
in columns in tables. A fundamental principle of the relational model is
that data is stored in this way and no other way (its called the 'information
principle').
So, taking your hypothetical example you'd have a table Colours with column
Colour. If this only contains the colours you want listed the control's
RowSource property would be:
SELECT Colour FROM Colours ORDER BY Colour;
If it’s a general purpose 'colour-chart' and contains more colours than
those to be listed you'd use:
SELECT Colour FROM Colours WHERE Colour IN("red","blue","yellow") ORDER BY
Colour;
It might not be quite so straightforward of course. Say for instance in an
international database you want to list all cities in the USA :
SELECT CityID, City, Region
FROM Cities INNER JOIN Regions
ON Region.RegionID = Cities.RegionID
WHERE Country = "USA"
ORDER BY Region, City;
The query used as the RowSource property here uses two tables Cities and
Regions, the former with CityID, City and RegionID columns, the latter with
RegionID, Region and Country columns (you'd also have a Countries table to
control data integrity, but its not necessary to use it in this context as a
Country column exists in the Regions table).
Note how it also returns a CityID column. This is the primary key of
Cities; City can't be used as the key because City names are duplicated (I
know there are at least 4 Staffords in the USA as well as the original one
where I live – we are twinned with them). This means the combo box has to be
set up as follows to hide the CityID column and show the names of the cities
and regions (states in the USA of course)
BoundColum: 1
ColumnCount: 3
ColumnWidths: 0cm;3cm;3cm
ListWidth: 6cm
If your units of measurement are imperial rather than metric Access will
automatically convert them. The important thing is that the first dimension
is zero to hide the first column. Its usually necessary to experiment with
the other two column widths dimensions to get the best fit. The ListWidth
should be the sum of the ColumnWidths dimensions.
Of course with the above example once a city is selected the relevant region
would not show in the combo box (a list box would show both columns all the
time of course), so the usual solution is to add an unbound text box control
to the form to show the region for the selected city, by making its
ControlSource property:
=[cboCity].[Column](2)
where cboCity is the name of the combo box. The Column property is
zero-based, so Column(2) is the third column, Region.
Ken Sheridan
Stafford, England