text box based on a dropdown value

C

Curtis

I have a text box that I need to auto populate after I select a value from a
dropdown box.
I have three tables-
Table 1 (Order) is set up like this:
OrderID
SupplierID
ItemID

Table 2 (Supplier) is set up like this:
SupplierID
SupplierName

Table 3 (Item) is set up like this:
ItemID
SupplierID
ItemName

For Example:
On the order form I have a dropdown box with the list of items (Table 3) and
then a text box for the supplier name corresponding to the item.

I need to set up my form where the supplier name will fill in automatically
after I select an item from the dropdown box.
 
K

Klatuu

Easiest way to do this is to change the row source of your combo to a query
based on a combination of Table 3 and Table 2. Make the combo a multicolumn
combo, then you will have the Supplier name already in a column in your row
source. So, say the columns in your row source are:
Col0 Col1 Col2 Col3
ItemID ItemName SupplierID SupplierName

Then, to get the supplier name, it would be Me.MyCombo.Column(3)
 
C

Curtis

Ok, I set up the query and linked it to my drop down box, but I am confused
on populating the textbox with the supplier name.

I tried adding the value in the On Change event.
Forms!Client!Order.Form!Supplier.Text = Me.ListCombo.Column(3)
It tells me "You can't reference a porperty or method for a control unless
the control has the focus"

I will need the value of the textbox to change every time I change the Item.
 
K

Klatuu

You will probably need to put the code in two places.
The After Update event of the combo box (The change event is not good,
because it does exactly what it is named, every time you type a character, it
fires) and the form's Current event.

Also, your syntax is incorrect:
Forms!Client!Order.Form!Supplier.Text = Me.ListCombo.Column(3)
Should be:
Me.Supplier = Me.ListCombo.Column(3)

You only need to qualify your controls if they are not in the form they are
in. For the form they are in, all that is needed is Me.ControlName

If you want to get the value of a control in another form:
forms!MyFormName!MyControlName

I
 

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