Populating the drop down box

G

Guest

I have created a form for adding data to a table. One of the fields in the
table is called "City". I have created a drop down box from which I want to
choose one of five cities.
However, I cannot figure out how to get the five city names into the drop
down box. I have tried combo box, list box, and drop down list box, and
cannot get the five names to show up in any of them.
Please tell me how to accomplish this.
 
G

Guest

Hi, Jim.

IMO, the best way is to create a table named Cities consisting of an
autonumber primary key and the city name. This makes it easy to add or
delete cities as your business may change.

Then simply add a combo box using the wizard, selecting both fields, and
choosing the Hide Key Field option. Store the selection (the foreign key) in
a numeric field in the form's underlying table. The city's name, however,
will display on the form because the wizard set the Bound Column property to
1, and the first Column Width to 0".

To enable the wizard, toggle the wand & stars button on the Toolbox toolbar.

The other property set by the wizard is the RowSource, which will be
something like:

SELECT Cities.CityCode, Cities.CityName FROM Cities;

to which you will probably want to add an ORDER BY clause to display the
cities in alphabetical order. You could also achieve this by creating a
query first that sorts them, and telling the wizard to use the query.

SELECT Cities.CityCode, Cities.CityName FROM Cities ORDER BY Cities.CityName;

Hope that helps.

Sprinks
 
F

fredg

I have created a form for adding data to a table. One of the fields in the
table is called "City". I have created a drop down box from which I want to
choose one of five cities.
However, I cannot figure out how to get the five city names into the drop
down box. I have tried combo box, list box, and drop down list box, and
cannot get the five names to show up in any of them.
Please tell me how to accomplish this.

If the 5 City names are fixed (never a need to add more cities), then
you can set the Combo Box Row Source Type property to Value List.
Set the Row Source to "Chicago", "New York", "Detroit", "Los
Angeles","Washington"

Set the Combo Box's Bound column to 1.
Set the Column Count to 1.
Set the Column Widths to 1".
Set the Control Source to [City].

If there might be a need to add additional cities, then use a table as
recommended by another replier.
 

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