Inserting values into a table from a combo box

newbie87

Registered User.
Local time
Today, 15:59
Joined
Sep 9, 2011
Messages
43
Hi,
I have an insert query that is causing me hassle.

Currently I have two tables Machine_Type and try

Machine_Type
ID Machine_Type
1 NM
2 NC
3 Esco
4 Rotary

the Machine_Type column populates a combo box (cmbMachine_Type) on my form so i can see what machines i have stored, and the add button allows me to insert the selected machine into the try table, but when i go to see the results in the try table, instead of inserting the Machine_Type chosen,
it inserts the row number the machine is on. For example I choose to add ESCO but instead of the text it inserts it as 3.

this is my insert statement
CurrentDb.Execute "Insert into try (Machine_Type) Values ('" & cmbMachine_Type & "');"

does anybody have any idea's?
 
Being as you did not explain what the "try" table is, I'm going to assume it holds only the description of the machine that you're attempting to add from your combo box.

Design flaws aside, the simple answer to the problem you're having is related to the Bound Column of your combo box. By default, your combo box will be bound to the first column of whatever it is tied to (in this case the ID). You need to change the Bound column property to 2 so that it will return Machine_Type instead.

Hope this helps.
Guy
 
Hey Guy,

Thanks for the fast response.

This sorted it out right way!!
 

Users who are viewing this thread

Back
Top Bottom