Good morning
An after update procedure of my Quotes form looks up the chargeout rate of the Employee based on their Employeeid, but returns an incorrect value - where the EmployeeID has more than one rate. The employee will have more than one rate as the rate will be effective from a point in time.
The rates are stored in a table "tblrates". I have tried sorting the table by effective date (descending) - but the dlookup still picks up the first value.
I can get around this by replacing the "tblrates" with the query "qryLabourlookup" that has the employeeid and the chargeout rate (ordered by effective date - desc). I cannot work out why referencing the table itself, the Dlookup gives the wrong value.
Help as always is appreciated.
Cheers
An after update procedure of my Quotes form looks up the chargeout rate of the Employee based on their Employeeid, but returns an incorrect value - where the EmployeeID has more than one rate. The employee will have more than one rate as the rate will be effective from a point in time.
The rates are stored in a table "tblrates". I have tried sorting the table by effective date (descending) - but the dlookup still picks up the first value.
I can get around this by replacing the "tblrates" with the query "qryLabourlookup" that has the employeeid and the chargeout rate (ordered by effective date - desc). I cannot work out why referencing the table itself, the Dlookup gives the wrong value.
Help as always is appreciated.
Cheers
Code:
Private Sub EmployeeId_AfterUpdate()
Dim strName As String
Dim strDocName As String, strDocName1 As String
Dim strFilter As String
On Error GoTo Err_EmployeeId_AfterUpdate
strName = "ChargeOutRate"
strDocName = "qryLabourlookup"
strDocName1 = "tblrates"
'Evaluate filter before it's passed to DLookup function
strFilter = "EmployeeId = " & Me!Employeeid
'Look up product's unit price and assign it to UnitPrice ontrol.
Me!UnitPrice = DLookup(strName, strDocName1, strFilter)
Exit_EmployeeId_AfterUpdate:
Exit Sub
Err_EmployeeId_AfterUpdate:
MsgBox Err.Description
Resume Exit_EmployeeId_AfterUpdate
End Sub