TextBox and Combo (1 Viewer)

endri81

Registered User.
Local time
Today, 14:36
Joined
Jul 5, 2010
Messages
121
Hi I have a textbox where I want to enter numbers 1.2..3.4. and a combobox where depended in what number I enter one city is chosen and stored in DB.
For example I want to enter 1 and in combobox to be chosen Boston which is the value to be stored in DB?
How to make this possible?
Regards
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:36
Joined
Jan 23, 2006
Messages
15,395
That's not the typical request. Usually, someone has a table of employees or customers. And they want to identify the location (say Country) of each Customer.
In that case, there are usually 2 tables. A Customer table and a CountryLookup table.

The CountryLookup table has fields such as
CountryID and CountryName with values such as

1 United States
2 Great Britain
3 Australia
4 Canada
.....

When completing a form with Customer records, a list box or combo box of CountryNames would be available. One would select a Country from the list, and the CountryID would be placed in the Customer table.


City and State example:
A variation is to have 2 combo boxes in the case of Cities and States.

Combo1 has a list of States, Combo2 has a list of City*States

One would select a State from Combo1, and behind the scene only Cities in the Selected State would be available for selection in Combo2. In effect a filter has been placed on Combo2, based on the value selected from Combo1. (This is known as Cascading Combos)

Once the City is selected, the State Code and The city code/name would be added to the table.

Is that what you are looking for?
 
Last edited:
Local time
Tomorrow, 07:36
Joined
Aug 8, 2010
Messages
245
i have sometimes come across this request where users learn the numbers and want to enter the number instead of the name.
You can have a table of city names with an autonumber primary key.
In the combo, you can use a query that shows both the autonumber pk and the city.
Make sure the 1st column of the combo is not hidden.
User can choose the number they want.

I am assuming that you only have a handful of cities in this database - otherwise how would users remember which number to pick? I am also assuming that the cities do not change over time.

I suggest that instead of storing the name of the city in the database, you store the pk. Every time you want to show the city to the user, you use a query and show the city instead of the pk.

if you have many cities and the cities can change over time, then the answer by jdraw would be more appropriate.
 

Users who are viewing this thread

Top Bottom