Using two fields from a combo box in two different fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a combo box on a form which links to a table with two fields:
CountryName and DialingCode. I want to be able to select the CountryName and
for it to store CountryName in a field on the form for CountryName, but also
to use the DialingCode to store in a field called DialingCode. I have tried
SetValue, but this didn't work. Any ideas gratefully accepted!
 
Super_Wife_Mon,

You can bind one control to only one table field directly, so you would
need a macro or some code to do this. The good news is you don't need to
do it - actually, you shouldn't! Duplication of data is not a good
idea... presumably you already have that information in a separate table
(tblCountries or something), where the combo box pulls it from, so
that's all you need; storing just the country name in the (contacts?
customers?) table, you can pull the dialing code from the countries
table anytime.
Picture this: you enter a wrong dialing code for a country, then create
30 contact records with it, then notice it's wrong... you'll have to go
back and correct it in each and every contact record. On the other hand,
keeping it in one place only, requires that you only correct it in that
one place, not only making life easier, but also helping maintain data
integrity (and also saving on storage space).

HTH,
Nikos
 
Thanks for that. Is there any way of simply displaying that field
(DiallingCode) in an unbound control so that the user can see it, but not
make any changes to it?
 
Super_wife_mom,

It is not a good idea to store the DialingCode in a field in the table
that your form is bound to. In fact, you should remove that field from
the table altogether. Based on the data in your lookup table (the one
that you are using for the Row Source of your combobox), if you know the
CountryName, you automatically know the DialingCode, and can always
retrieve it via a query any time you need it for your database purposes,
so it is not really valid to store this related data another time.
However, you want to *display* it on your form, that's understandable.
There are a number of approaches that can be taken to this, and some of
them are explained in this article...
http://accesstips.datamanagementsolutions.biz/lookup.htm
Please have a read through the article, and then post back if you need
more help.
 
Actually, several ways to choose from. Look at Steve Schapel's reply to
your original post.

Nikos
 
Thanks Steve. This worked a treat! :-)

Steve Schapel said:
Super_wife_mom,

It is not a good idea to store the DialingCode in a field in the table
that your form is bound to. In fact, you should remove that field from
the table altogether. Based on the data in your lookup table (the one
that you are using for the Row Source of your combobox), if you know the
CountryName, you automatically know the DialingCode, and can always
retrieve it via a query any time you need it for your database purposes,
so it is not really valid to store this related data another time.
However, you want to *display* it on your form, that's understandable.
There are a number of approaches that can be taken to this, and some of
them are explained in this article...
http://accesstips.datamanagementsolutions.biz/lookup.htm
Please have a read through the article, and then post back if you need
more help.
 
Back
Top