Hi all
I stole some code from the Northwind DB to use in my own invoicing DB. I don't normally use code because I have enough trouble getting my head around the basics of access without delving into the dark & mysterious world of secret languages, so forgive my ignorance.
I have used the code to automatically update a cost field when a certain choice is made in a combo box on a sub-form (its displayed as a datasheet)
Everytime I make a choice the cost field is updated for that record with the same costs as the previous record. All I can assume is that its the code & in my butchering of it to suit my requirements I've inadvertently mucked it up. Can someone please have a look & see if you can spot any errors that may cause the above?
Thanks in advance gurus.
Private Sub ConsumableListID_AfterUpdate()
On Error GoTo Err_ConsumableListID_AfterUpdate
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "ConsumableListID = " & Me!ConsumableListID
' Look up product's unit price and assign it to UnitPrice control.
Me!Cost = DLookup("Cost", "Tbl_ConsumablesList", strFilter)
Exit_ConsumableListID_AfterUpdate:
Exit Sub
Err_ConsumableListID_AfterUpdate:
MsgBox Err.Description
Resume Exit_ConsumableListID_AfterUpdate
End Sub
Cheers
Mik
I stole some code from the Northwind DB to use in my own invoicing DB. I don't normally use code because I have enough trouble getting my head around the basics of access without delving into the dark & mysterious world of secret languages, so forgive my ignorance.
I have used the code to automatically update a cost field when a certain choice is made in a combo box on a sub-form (its displayed as a datasheet)
Everytime I make a choice the cost field is updated for that record with the same costs as the previous record. All I can assume is that its the code & in my butchering of it to suit my requirements I've inadvertently mucked it up. Can someone please have a look & see if you can spot any errors that may cause the above?
Thanks in advance gurus.
Private Sub ConsumableListID_AfterUpdate()
On Error GoTo Err_ConsumableListID_AfterUpdate
Dim strFilter As String
' Evaluate filter before it's passed to DLookup function.
strFilter = "ConsumableListID = " & Me!ConsumableListID
' Look up product's unit price and assign it to UnitPrice control.
Me!Cost = DLookup("Cost", "Tbl_ConsumablesList", strFilter)
Exit_ConsumableListID_AfterUpdate:
Exit Sub
Err_ConsumableListID_AfterUpdate:
MsgBox Err.Description
Resume Exit_ConsumableListID_AfterUpdate
End Sub
Cheers
Mik