Forum Discussion
Tony2021
Nov 10, 2024Iron Contributor
Dlookup - 3 criteria
Hello Experts, I am trying to use Dlookup with 3 criteria. The attached excel file is clearer but I will try to explain. What I need to return is the qryFacilityBal.[Balance] where "ProjI...
- Nov 10, 2024
I don't really follow the logic behind that, but I think this should do it:
Public Function GetBalance(dtmFundingDate as Date, lngProjID As Long, lngFacID As Long) As Currency Dim varDateAmend as Variant Dim strCriteria as String strCriteria = "DateAmend <= #" & Format(dtmFundingDate,"yyyy-mm-dd") & "# And " & _ " ProjIDfk = " & lngProjID & " And IDFacfk= " & lngFacID varDateAmend = DMax("DateAmend","qryFacilityBal",strCriteria) If Not IsNull(varDateAmend) Then strCriteria = "DateAmend = #" & Format(varDateAmend,"yyyy-mm-dd") & "# And " & _ " ProjIDfk = " & lngProjID & " And IDFacfk = " & lngFacID GetBalance = DLookup("Balance","qryFacilityBal",strCriteria) Else strCriteria = "ProjIDfk = " & lngProjID & " And IDFacfk= " & lngFacID varDateAmend = DMin("DateAmend","qryFacilityBal",strCriteria) strCriteria = "DateAmend = #" & Format(varDateAmend,"yyyy-mm-dd") & "# And " & _ " ProjIDfk = " & lngProjID & " And IDFacfk = " & lngFacID GetBalance = DLookup("Balance","qryFacilityBal",strCriteria) End If End Function
Tony2021
Nov 10, 2024Iron Contributor
Hello experts, thank you for the responses.
I have developed a database that I think will facilitate
Please take a look at Q1 (the dlookup field). YOu can see it is not correct.
Ken, if could maybe apply your solution would be excellent. I dont really want to use dlookup but that is what I have used and I know dlookup slows the processing time. I am sure you solution is a better strategy. I can apply it on my production db.
let me know if any questions.
Tony2021
Nov 10, 2024Iron Contributor
it looks like the accdb did not attach.