You need to have an AfterUpdate event procedure attached to the control that holds the value you want to look up. Let's say that's a combo box named cboProductID, and that it holds a product number that matches the ProductID field in tblStock. The field you want to get from tblStock is named Price. Your AfterUpdate event procedure then looks like this:
Code:
Private Sub cboProductID_AfterUpdate()
Me.Price = DLookup("Price", "tblStock", "ProductID = '" & Me.cboProductID & "'")
End Sub
What this does is look up the "Price" column in the "tblStock" table, in the row where the "ProductID" column has a text value equal to the contents of the cboProductID control. The value obtained is entered into the Price field on the form.
Note: If your ProductID (or whatever it's called) is a numeric value, rather than a text value, remove the two single quotes in the statement above. Rick Sprague
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.