Prepopulating fields (1 Viewer)

Aaron Senft

New member
Local time
Today, 23:34
Joined
Jan 4, 2000
Messages
8
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

Registered User.
Local time
Today, 17:34
Joined
Nov 3, 1999
Messages
31
Where is the cost coming from. (What table?)
Is it the table with the drop box or another?
 

Travis

Registered User.
Local time
Today, 15:34
Joined
Dec 17, 1999
Messages
1,332
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.
 

Users who are viewing this thread

Top Bottom