I have been working on this for about an hour and can't get the function to run without errors. I am using Allen Browne's ELOOKUP function from this page.
Here is the code currently calling the public function:
Dim r As Double
Dim Q1 As Double
Dim i1 As Double
r = Me!txtRepeat
Q1 = Me!txtQty1
i1 = ELookup("dblIndex", "zhqry_ActiveGrid_3_Final", "dblRepeat = " & r & " AND dblQuantity <= " & Q1, "dblQuantity DESC")
I get the error "Too few parameters: Expected 1."
I have stepped through the code and was able to extract strSQL which was:
SELECT TOP 1 dblIndex
FROM zhqry_ActiveGrid_3_Final
WHERE dblRepeat = 12 AND dblQuantity <= 55
ORDER BY dblQuantity DESC;
The actual error is thrown on this line of the ELOOKUP function:
Set rs = db.OpenRecordset(strSql, dbOpenForwardOnly)
I have tried:
- Encapsulating all field names in square brackets. Same error.
- Adding single quotes around my criteria values. Same error.
- Changed function line:
Set db = DBEngine(0)(0)toset db = CurrentDb, Same error. - Changed
dbOpenForwardOnlytodbOpenSnapshot. Same error.
I copied the strSQL value into Access's query builder and it ran fine so I know that I am building a valid string. I am using Access 2010.
What am I doing wrong?
Set rs = db.OpenRecordset(strSql)- Gary Evanszhqry_ActiveGrid_3_Final(or a subquery of it) have parameters like e.g.Forms!myForm!myValue? They are evaluated when opening the query in Access, but not when opening a recordset on it. -- See "Limitations of ELookup(): ... DLookup() can call the expression service to resolve an argument.." - Andre