Public Function EmpWNIS(inpGross As Double, inpWDate As Date, inpRDate As Variant) As Double
Static dblValue As Double
Static strValue As String
Dim strNewValue As String
Dim strPeriodEnd As String
Dim strWENIS As String
Dim RetDate As Date
RetDate = IIf(inpRDate = 0, inpWDate, inpRDate)
strPeriodEnd = "#" & Format(inpWDate, "m/d/yyyy") & "#"
' arnelgp
' check if stValue has changed
'_____________________________
strNewValue = Format$(RetDate, "yyy-mm-dd") & Format$(inpWDate, "yyyy-mm-dd") & Format$(inpGross, "000000.00")
If strValue <> strNewValue Then
' assign strNewValue to strValue
strValue = strNewValue
strWENIS = "SELECT TOP 1 * FROM tblNIS WHERE [EffDate] <= " & strPeriodEnd & " And WRange <= " & inpGross _
& " ORDER BY [EffDate] DESC , WRange DESC"
With CurrentDb.OpenRecordset(strWENIS)
If Not (.BOF And .EOF) Then
If RetDate < inpWDate Then
dblValue = 0
Else
dblValue = !ENIS
End If
End If
End With
End If
EmpWNIS = dblValue
End Function