MajP
You've got your good things, and you've got mine.
- Local time
- Today, 11:53
- Joined
- May 21, 2018
- Messages
- 9,207
Here is another useful example.
I made a function to get the additive score. This could be used in place of the more complex query.
I can test this function and verify the somewhat complex criteria and see if I get the correct result.
In the immediate window
AdditiveID = 1 AND 10 >= RangeStart AND 10 < RangeEnd
3
So for urgency and a value of 10 I get a score of 3 which is correct because it is between 6 and 12. Debug.print is the most useful thing to debug your code.
I made a function to get the additive score. This could be used in place of the more complex query.
Code:
Public Sub test()
Debug.Print GetAdditiveScore(1, 10)
End Sub
Public Function GetAdditiveScore(AddID As Variant, AddValue As Variant) As Integer
If Not IsNull(AddValue) And Not IsNull(AddID) Then
Dim strWhere As String
strWhere = "AdditiveID = " & AddID & " AND " & AddValue & " >= RangeStart AND " & AddValue & " < RangeEnd"
Debug.Print strWhere
GetAdditiveScore = Nz(DLookup("score", "additiveRanges_T", strWhere), 0)
End If
End Function
I can test this function and verify the somewhat complex criteria and see if I get the correct result.
Code:
Public Sub test()
Debug.Print GetAdditiveScore(1, 10)
End Sub
In the immediate window
AdditiveID = 1 AND 10 >= RangeStart AND 10 < RangeEnd
3
So for urgency and a value of 10 I get a score of 3 which is correct because it is between 6 and 12. Debug.print is the most useful thing to debug your code.