Aaron Senft
01-04-2000, 01:43 PM
I have a database where I have a drop down list that is populated from another table. What i want to do is when i select item in the drop down list, i want it to take the corresponding cost and put it in another field. Anyone know how to do this? Thanks!
Aaron Senft
eason
01-04-2000, 07:22 PM
Where is the cost coming from. (What table?)
Is it the table with the drop box or another?
Travis
01-04-2000, 08:05 PM
If you have the cost as one of the Columns of the Combobox you can easily add this code on the AfterUpdate of the ComboBox:
Private Sub MyComboBox_AfterUpdate()
'Assuming Item is in column(1) and Price is in Column(2)
Me.[MyPriceField] = Me.[MyComboBox].Column(2)
End Sub
Otherwise you will have to add code that retrieves the value for the item and add this code to the AfterUpdate of the ComboBox.
Private Sub MyComboBox_AfterUpdate()
Me.[MyPriceField] = Currentdb.OpenRecordset("Select [Price] from tblWherePriceIsStored where Item = " & Me.[MyComboBox]).Fields(0)
End Sub
For speed I recommend having the Price as one of the columns in the ComboBox. You can make its column width Zero if you don't want to see the Price when they are Using the ComboBox.