How do I populate a text box based on a combo box?

G

Guest

I have a form with a combo box ( Customers ) I would like the address field
to fill in automatically based on the selection chosen in the combo box. How
do I make this happen? Please help
 
V

Van T. Dinh

Have a look at the Orders Form in the sample database "NorthWind". This
shows 2 different methods of filling a TextBox from the selection of a
ComboBox. Note that these 2 methods are use differently: the Mailing
Address Controls are Calculated Controls (uneditable) and the Delivery
Address Controls are bounded Controls (editable).
 
G

Guest

Jason,

Van, as usual, gives excellent advice. Also note that forms don't have
*fields*-- which are table attributes where data is stored--they have
*controls*, where data is displayed. If the control is bound to a field
(that is, its ControlSource property is set to the name of a field in the
form's underlying RecordSource), then what is entered into the control will
also be saved to the field.

In your case, however, the address associated with the chosen customer is
fully defined in the Customer table, and therefore is not needed to be stored
in the table underlying your form. You just need to display it as helpful
information.

The distinction between a form or report control and a field is an important
one. Fields have a datatype--text, integer, Date/Time, etc. Controls do not
have a datatype; they are just a data container that can either be Bound to
an underlying field, in which case the data entered into the control is saved
to the field, or they can be unbound.

Hope that helps.
Sprinks
 
G

Guest

I understand the difference between the fields and controls although I didn't
make that clear above. I've looked at the orders form in the Northwind
database and am still not sure what I'm missing. What I want to have happen
is when I select the customer from the combo box ( Which is based on a
customer table ) I want the address to show in the control for the customer
address. I'm printing the form itself as a work order for my service
technicians to take on calls with them.
 
G

Guest

Jason,

Either:

1. Base your form on a query linking your table and the Customer table by
CustomerID, and include the Address field in the recordset. Do NOT include
the CustomerID from the Customers table or the recordset will be
non-updateable.

2. Include the address as a column in the RowSource of your combo box, and
display it in a textbox using the combo box' Column property.

Combo Box RowSource:
SELECT Customers.ID, Customers.Name, Customers.Address FROM Customers ORDER
By Customers.Name;

Textbox ControlSource:
=YourComboBoxName.Column(2)

2 is the column number, beginning with zero.

Hope that helps.
Sprinks
 
G

Guest

Thank you both, between the input you both gave I'm now able to do what I
wanted to. Hopefully I can pass some knowledge onto other as you have done.

Thanks,
Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top