Using a combobox to fill a textbox

cunnie

Registered User.
Local time
Today, 08:35
Joined
Apr 11, 2002
Messages
24
I've got a combobox that has 4 coloums (lets call them A B C and D)

D is the primary key and is a 'code' e.g.001 (unique)
A is the value that is shown in the combobox window (this field has duplicates)

now, after i select an option from the combobox I click a button. I need this button to copy field B to a textbox where field d is equal to the one selected in the combobox.

Any ideas?
 
For your text box, use this as the recordsource:
=Me.comboFieldName.Column(1)

Then lock and disable the field, since no one will be editing it anyway. Comboboxes count from 0 so the 2nd column is (1), etc. Adjust as necessary.

HTH,
David R
 
It would be better to reformat your combo box to show D A B C. Do this by setting the column order in the underlying query as most relationships will relate to the ID field and the combo (by default) will bind to the first column.
If you want to store this value (A) in another field, in the after_update field of the combo, set the event procedure to
Me.NameofTextbox = Me.NameOfCombo.Column(1) (given order D A B C)
If you just want to show the value, set the controlsource of the textbox to =Forms!NameofForm!NameofCombo.Column(1)

HTH

Edit: Damn, DavidR must be able to type with both hands
wink.gif


[This message has been edited by Fizzio (edited 04-11-2002).]
 
cheers guys, works a treat!

I left column D where it was because to the user the PK would mean nothing, I see where you're coming from tho
wink.gif


OH NO!
wait a minute, it doesn't work. It just shows the values from the record at the top of the combobox even if you select another. :s

[This message has been edited by cunnie (edited 04-11-2002).]
 
Order the query/SQL that your combo is based on so that the PK is first. Then make sure the Bound Column is 1, and the Column Widths something like: 0";1.456";1.2";0.567"

The first one being 0" will hide your PK from view. Bound column being 1 (combos count from 0 for some reason) means the displayed column will be the 2nd.

It might be easier at this point to redo the combo box. The combo box wizard is quite good about getting all of this stuff set up properly, including storing values w/o extra code. Then worry about your Column(2) text box.

HTH,
David R
 
Which method did you choose, showing or storing the value as I described above?
 
ended up using the show method.
Got it working fine now, cheers guys!

PS-The column didn't start counting from zero it started from one, wierd!

[This message has been edited by cunnie (edited 04-12-2002).]

[This message has been edited by cunnie (edited 04-12-2002).]
 

Users who are viewing this thread

Back
Top Bottom