I am using 2 forms. The first is a simple single table form that manages a key table called "Function". The second is a form with a sub-form. The main form is bound to the "Function" table with the sub-form managing a table called "Category".
The sequence of presentation for other forms and reports is critical for the data in both tables and each has a column called "ListNo" which is managed by the system administrator. Owing to processes in the system IT IS CRITICAL that the "ListNo" in both tables be unique and I wrote 2 simple virtually identical functions that attempt to open a recordset using a count query that simply counts the number of times each "ListNo" is used then validates that the counts do not exceed 1 ... see code below.
Should be easy stuff however the "Function" one works and the "Category" one does not. More importantly the "Category" one fails with a run-time error indicating that it cannot find the required first parameter which in this case is a query name or its SQL string. I have tried both ... they both produce the same error yet in other identical other function it works fine. Run-time error '3061': Too few Parameters. Expected 1. on the Set rs = db.OpenRecordset ("queryname") command that clearly provides the requested parameter.
Here's the code for the one that doesn't work ...
Code:
Public Function validateCategoryListNos()
Dim db As Database, rs As Recordset
Dim SQL As String
Set db = CurrentDb
'Set rs = db.OpenRecordset("CatDupListNoCheck")
Set rs = db.OpenRecordset("SELECT Count(tblCategory.ListNo) AS CountOfListNo FROM tblCategory GROUP BY tblCategory.Function, tblCategory.ListNo HAVING (((tblCategory.Function)=[TempVars]![FuncID])) ORDER BY Count(tblCategory.ListNo) DESC;")
rs.MoveFirst
'If value of 1st record >1 then problem
[TempVars]!
[ListDup] = False
If rs.Fields(0) > 1 Then
[TempVars]!
[ListDup] = True
End If
rs.Close
db.Close
End Function
Appreciate any help. Thanks