I have created a MS access DB to track transport costs for tax purposes.
I enter data into a main form [F_car] that tracks miles traveled by date with a subform [F_tolls subform]. The subform has fields for the date traveled [date], toll location [toll site] and the cost of the toll [cost]. The date on the subform is copied from the main form. [toll site] is a combo box that draws its values from [toll name] in the [key- Toll codes] table, which also has the fields -Toll ID, Toll text, and toll cost).
My question is regarding the [cost] control on the subform. I would like the cost to be filled in automatically from the [key- Toll codes] table [toll cost] field whenever a toll location is chosen from the combo box.
Being a beginner user of Access, I looked to the Internet for help and have been unsuccessful in trying the following:
-using the following Dlookup function as the control source for the cost text box
=DLookUp("[Toll cost]","Key-Toll codes","[Toll name] = ' " & [Tolls site] & " ' ")
- using the following after update event procedure with the [toll site] combo box
Private Sub Tolls_site_Afte rUpdate()
Me![Cost] = DLookup("[Toll cost]", "Key-Toll codes", "[Toll name] = ' " & [Tolls site] & " ' ")
End Sub
Can someone suggest the right way to do this?
I enter data into a main form [F_car] that tracks miles traveled by date with a subform [F_tolls subform]. The subform has fields for the date traveled [date], toll location [toll site] and the cost of the toll [cost]. The date on the subform is copied from the main form. [toll site] is a combo box that draws its values from [toll name] in the [key- Toll codes] table, which also has the fields -Toll ID, Toll text, and toll cost).
My question is regarding the [cost] control on the subform. I would like the cost to be filled in automatically from the [key- Toll codes] table [toll cost] field whenever a toll location is chosen from the combo box.
Being a beginner user of Access, I looked to the Internet for help and have been unsuccessful in trying the following:
-using the following Dlookup function as the control source for the cost text box
=DLookUp("[Toll cost]","Key-Toll codes","[Toll name] = ' " & [Tolls site] & " ' ")
- using the following after update event procedure with the [toll site] combo box
Private Sub Tolls_site_Afte rUpdate()
Me![Cost] = DLookup("[Toll cost]", "Key-Toll codes", "[Toll name] = ' " & [Tolls site] & " ' ")
End Sub
Can someone suggest the right way to do this?
Comment