Listbox-multiple selections

J

Jane

Hi all,

I am creating a table at the moment with the field name "what is the weather
like today?" I am creating a list box with the options: Warm, cold, wet, dry,
windy, icy, snowing..... How can I allow the user to select more than one
option, or restrict them to selecting only one option? Am not even sure if
this should be a listbox or not.

Any help would be greatly appreciated.

Thanks
Jane
 
D

Daniel Pineault

Open the formin design mode
Open the properties dialog for the Listbox
Goto the 'Other' tab
Set the 'Multi Select' property to either the appropriate value based on
your needs

None - single value
Simple and Extended permit multiple selection of values

Select the property and then press F1 to get the help on the Multi Select
property for more details
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
W

Wayne-I-M

Hi Jane

The very basic idea of an access table is that each field in a reocrd
contains only bit of information. If you ask what is the wether like you may
get Warm, Raining, Windy. - which is really 3 bits.

So you may want to create fields
Temp = Warm, Cold, V Cold, etc
Wind = Nil, Slight, Some, Strong. etc
Rain = Nil, Some, Slight, Lots, etc.

Note - these are not lookup fields. Just format them as text (I assume
there is only a limited number of options for each)

Create a form and put some combo boxes on it.
Source = value (this is where you would your wethewr options in each)

Id you add the date and location to the table you would have a (non-exact)
record for each

You may want to create another table for location and link it to your other
table so you can get different people's idea of the wether in the same
locaiton.

Good luck
 
K

Ken Sheridan

Jane:

Firstly do not use a multi-select list box for entering data unless you are
prepared to write a lot of code behind your form to insert data into a table/
read data from a table. Multi-select list boxes are really designed for
querying the database rather then entering data, e.g. you might want a report
of which days have experience all of a set of selected weather conditions,
for which a multi-select list box would be the right tool, but there are far
better and easier ways of entering the data. Examining two scenarios:

1. If you have a fixed set of weather conditions e.g. temperature,
precipitation, wind strength etc the Wayne's solution is fine, having one
column (field) for each in the WeatherLog (or whatever) table, along with
columns for the date, location etc. Each combo box should get its list from
another table:

WeatherConditions
….Condition (primary key)
….Category (foreign key referencing Categories table)

so the RowSource type for the Precipitation combo box would be:

SELECT Condition FROM WeatherConditions WHERE Category = "Precipitation"
ORDER BY Condition;

and that for temperature would be:

SELECT Condition FROM WeatherConditions WHERE Category = "Temerature" ORDER
BY Condition;

2. However, if you want to record a variable set of weather conditions per
day then a better solution would be to have two related tables which in turn
would reference other tables, e.g.

WeatherLog
….WeatherLogID (autonumber primary key)
….WetaherLogDate
….LocationID (foreign key referencing a Locations table)
….RecorderID (foreign key referencing a Recorders table)

WeatherLogDetails
….WeatherLogID (foreign key referencing the WeatherLogtable)
….Condition (foreign key referencing WeatherConditions table)

The primary key of the above table would be composite one of WeatherLogID
and Condition. What this table is really doing is modelling a many-to-many
relationship between WeatherLog and Conditions by resolving it into two
one-to-many relationships.

WeatherConditions
….Condition (primary key)
….Category (foreign key referencing Categories table)

Categories
….Category (primary key)

This last table would have values in the Category column for Temperature,
Precipitation, Wind Strength etc.

For data entry you'd use a form, in single form view, based on the
WeatherLog table, and within it a subform, in continuous form view, based on
the WeatherLogDetails table. To enter each condition to be recorded for the
day a new row would be inserted in the subform, selecting from a combo box
bound to the Condition column. The combo box's RowSource would be:

SELECT Category, Condition FROM WeatherConditions ORDER BY Category,
Condition;

its other properties would be:

BoundColumn: 2
ColumnCount: 2
Column Widths: 2.5cm;2.5cm

You'll need to experiment with the last to get the best fit. It you are
using inches rather than metric units Access will automatically convert the
above (2.5cm = 1 inch approx)

To show the category for the selected condition include an unbound text box
in the subform, with a ControlSource of:

=cboCondition.Column(0)

where cboCondition is the name of the combo box bound to the Condition column.

Finally one or two explanatory points:

1. You might be wondering why you need the WeatherConditions and categories
tables at all as you could simply use value lists as the RowSources of the
cmbo boxes. The reason is that the conditions and categories are data, and
it’s a fundamental rule of the databases relational model that data is stored
as values at column positions in rows in tables and in no other way. Value
lists should only be used for sets of values immutably fixed in the external
world, such as days of the week or months of the year.

2. You might also be thinking that the Categories table is surplus to
requirements as the category for each condition is in the Conditions table.
The reason is that it allows you to create a relationship between Categories
and Conditions and enforce referential integrity and cascade updates. The
former ensures that only valid categories can be entered in Conditions, the
latter means that if you change the name of a category, e.g. you might decide
to change Precipitation to Rainfall in the Categories table (rather
inaccurately of course). This would automatically update all the
Precipitation rows in Conditions to Rainfall.

Ken Sheridan
Stafford, England
 
K

Ken Sheridan

Jane:

One correction to my reply. The combo box for selecting the weather
condition in the subform would be set up as follows:

RowSource: SELECT Condition, Category FROM WeatherConditions ORDER BY
Category, Condition;

its other properties would be:

BoundColumn: 1
ColumnCount: 2
Column Widths: 2.5cm;2.5cm
ListWidth: 5cm

and the text box to show the category would have a ControlSource of:

=cboCondition.Column(1)

I'd got the two columns the wrong way round. I'd also omitted the ListWidth
property, which should be the sum of the ColumnWidths dimensions.

Ken Sheridan
Stafford, England
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top