Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate the value of a Text Box based on the value in a Combo Box in MS Access 2007?

I have a combo box which is of a lookup type, i.e., I've selected the source to be a column from a table and am storing the selected value in another table. The table which I am looking up has another column and I need the value in this column to be displayed in a text box and each time I change the value in the combo box, I need the corresponding value to be displayed in the text box. How can I do this? What I have done so far is to write a Select query that selects the appropriate column based on the combo box's value. Is there a more decent way of doing this? Please help me!

like image 790
CodingInCircles Avatar asked Jun 21 '11 09:06

CodingInCircles


2 Answers

Make the source of the combo box to your 2 fields e.g. SELECT id, name FROM Customers
Make sure you set the Column Count property of the combo to 2, accordingly.
Then make you unbound text box source equal to =MyCombo.Column(1) (from memory, this Column is zero based).
That's it, zero code required.

like image 150
iDevlop Avatar answered Sep 18 '22 00:09

iDevlop


It's nicer to use an event of the combo box e.g. onChange, so when a selection is made the event sets the value of the text box.

me!txtTextBox1 = me!cboComboBox1.column(1)

That way it will work everytime.

You could also use a button with onClick etc. but the choice is yours (and as mentioned in the previous post, alter the column number based on its row source with 0 being the first.

like image 37
Mart Avatar answered Sep 22 '22 00:09

Mart