SQL - what's wrong here
I have a field (Count) on my form (NN_ON) that displays the number of records returned by the SQL below. The parameter for the SQL comes from a field on my form (NN_ON) called (srID).
I get a runtime error 3061 "To few parameters expected 1", if the WHERE clause is directed to the field (srID) as below.
Dim Database As DAO.Database
Dim rst As DAO.Recordset
Dim dbs As Database
Dim rstSQl As String
Dim MyF As Form
Set dbs = CurrentDB
Set MyF = [Form_NN_ON]
rstSQl = "SELECT tblStockClerk.[stockroomID], tblStockClerk.[stock clerk]" _
& "FROM tblStockClerk WHERE tblStockClerk.[stockroomID] = MyF.srID;"
Set rst = dbs.OpenRecordset(rstSQl)
rst.MoveFirst
Do While Not rst.EOF
rst.MoveNext
Loop
Forms![NN_ON]![Count] = rst.RecordCount
If I substitute an actual stockroom ID number in the WHERE clause i.e. WHERE tblStockClerk.[stockroomID] = 11410, it works fine and returns the correct record count.
What am I missing?
I have a field (Count) on my form (NN_ON) that displays the number of records returned by the SQL below. The parameter for the SQL comes from a field on my form (NN_ON) called (srID).
I get a runtime error 3061 "To few parameters expected 1", if the WHERE clause is directed to the field (srID) as below.
Dim Database As DAO.Database
Dim rst As DAO.Recordset
Dim dbs As Database
Dim rstSQl As String
Dim MyF As Form
Set dbs = CurrentDB
Set MyF = [Form_NN_ON]
rstSQl = "SELECT tblStockClerk.[stockroomID], tblStockClerk.[stock clerk]" _
& "FROM tblStockClerk WHERE tblStockClerk.[stockroomID] = MyF.srID;"
Set rst = dbs.OpenRecordset(rstSQl)
rst.MoveFirst
Do While Not rst.EOF
rst.MoveNext
Loop
Forms![NN_ON]![Count] = rst.RecordCount
If I substitute an actual stockroom ID number in the WHERE clause i.e. WHERE tblStockClerk.[stockroomID] = 11410, it works fine and returns the correct record count.
What am I missing?