copy record from same field in different object

S

seth

i am trying to figure out a way to copy another field from the same record
to a different object.
for example, let's say i have a table with two fields, country and
country_code
i want to create a form with a drop down list getting the values from
country (which i've done) and have a label that would display the
corrosponding code
so if on the form i selected "france" the lable value would automatically
change to "+33" or if i select "colombia" the value would change to "+57"
etc.
i know it's probably possible but haven't gotten it yet. any help
appreciated
 
R

rowiga

If you're pulling "Country" from the table for the combo box, pull the
"CountryCode" at the same time. CountryCode should be the second column shown
in your combo box.

In the AfterUpdate event for the combo box use code similar to this:

Me.MyTargetFieldName = Me.MyComboBoxName.Column(1, 0)

Since Access numbers the columns in the combo box as 0, 1, 2 etc,
CountryCode will be written to your desired control on the form whenever a
new value is selected from the combo box for Country.
 
S

seth

ok, it partially works
if i select a country, the label is updated, but only once. if i select a
different one, it doesn't update
closing the form and opening it again will change it the first time, but not
on subsequent changes
 
J

John Vinson

so if on the form i selected "france" the lable value would automatically
change to "+33" or if i select "colombia" the value would change to "+57"
etc.

Rather than using a label, use an unbound Textbox; set its Control
Source property to

=cboCountry.Column(1)


John W. Vinson[MVP]
 
R

rowiga

Sorry Seth...change the code to:

Me.MyTargetFieldName = Me.MyComboBoxName.Column(1)
 
Top