Error opening recordset. Too few parameters. Expected 1.

  • Thread starter Thread starter Reg
  • Start date Start date
R

Reg

I get this error when feeding the following SQL string to
an openrecordset statement. Any ideas?

EditSQLStrChq = "SELECT (tblCheques.ChequeNumber) FROM
(tblCheques) WHERE ((tblCheques.ChequeNumber)
=ChequeNumberVoid)"
Set CChequeTablerecset = CDb.OpenRecordset(EditSQLStrChq)

ChequeNumberVoid is just an integer like 123.
Thanx in advance.
 
Access is complaining about ChequeNumberVoid. It has no idea what this is in
the SQL statement. Try the following.

EditSQLStrChq = "SELECT (tblCheques.ChequeNumber)
FROM (tblCheques)
WHERE ((tblCheques.ChequeNumber)=" & ChequeNumberVoid & ")"
 
EditSQLStrChq = "SELECT (tblCheques.ChequeNumber)
FROM (tblCheques)
WHERE ((tblCheques.ChequeNumber)=" & ChequeNumberVoid & ")"

I don't understand the purpose of this query: you are sending it a
ChequeNumber and getting the same ChequeNumber back.

If you want to know whether the ChequeNumber exists, you can do the quicker
and safer:-

"select count(*) from tblCheques " & _
"where chequenumber = " & chequenumbervoid & ";"

or just

DCount("*","tblCheques", "Chequenumber = " & chequenumbervoid)

or this is neater, because you get yes/ no answer:

"SELECT COUNT(*)=0 AS NotFound " & _
"FROM tblCheques " & _
"WHERE ChequeNumber = " & ChequeNumberVoid & ";"

Rule eleven: get the server to do the work, not the application!

All the best


Tim F
 
Back
Top