Combo Box and Sql Code

H

heinerAJ

I am very new to this, but this is what I would like to do.

I have a combo box that has for a control source a query that selects
customer names. An extended part of my form then contains unbound text
boxes. I have been trying to, upon the change of the combo box, change the
values of the unbound text boxes.

In my attempt to accomplish this I coded in the "On Change" event for my
combo box a SQL statement:
Me.Zipcode = "SELECT Customer_Information.Zipcode FROM Customer_Information
WHERE Customer_Information.Customer_ID = " & Customer_Name.Value

When it runs I select the customer I want from the combo box and the zipcode
text box displays the entire sql statement with the Customer_Name.Value
changed to its actual value. This value ends up being the Customer_ID.

How can I get the correct value to be extracted from the database?
 
A

Allan Murphy

Suppose your combo box is called cmbcust_name, your unbound field is called
zipcode, now in your combo box you have a record source
that will display a list of Customer names, now add a column that will
display the zipcodes. You do not need to display this column.

Then on the On Change event of the combo box add the following.
me!zipcode=cmbcust_name.column(1)
Note: cmbcust_name.column(0) is the first column of your query which is your
customer name
 
Top