StevenFromSouth
Programmer
Hello, new member here.
I'm not too good when it comes to queries but I wanted to stop using DLookups, I've read that they can be highly inefficient and unstable. I saw some posts on this forums and Allen Browne have emphasized that joined queries and subqueries are far superior.
I have a Products table
UPC, ItemName, Measurement
Prices Table
UPC, EffDate, Quantity, Price, Discount
I am using this function to get the Current Price for a given Product
Can anyone guide me to converting this to a query?
I'm not too good when it comes to queries but I wanted to stop using DLookups, I've read that they can be highly inefficient and unstable. I saw some posts on this forums and Allen Browne have emphasized that joined queries and subqueries are far superior.
I have a Products table
UPC, ItemName, Measurement
Prices Table
UPC, EffDate, Quantity, Price, Discount
I am using this function to get the Current Price for a given Product
Code:
Public Function GetPrice(inpUPC As Double, inpQuantity As Double, inpDate As Date) As Double
On Error Resume Next
Dim strPrice As Double
Dim strRegPrice As Double
Dim strDiscount As Double
Dim strMaxDate As Date
inpDate = Format(inpDate, "m/d/yyyy")
strMaxDate = DMax("EFFDATE", "Prices", "UPC= " & inpUPC & " AND EFFDATE<= # " & inpDate & " # And Quantity= " & inpQuantity & " ")
strPrice = DLookup("Price", "Prices", "UPC= " & inpUPC & " And EFFDATE= #" & strMaxDate & " # And Quantity= " & inpQuantity & " ")
strRegPrice = DLookup("Price", "Prices", "UPC= " & inpUPC & " And EFFDATE= #" & strMaxDate & " # And Quantity= 1 ")
If GetDiscount(inpUPC, inpQuantity, inpDate) = 0 Then
GetPrice = strRegPrice
Else
GetPrice = strPrice
End If
End Function
Can anyone guide me to converting this to a query?