Re: SQL syntax

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Edward wrote:
Hello

I'm receiving a 'Too Few Perameters. expected 1' error when trying to use a variable in place of a number in a Where statemet of an SQL string.

------ code
Private Sub cmdOutput_Click(Index As Integer)
Dim DB As Database, RS As DAO.Recordset
strSQL = "SELECT tblOutPoints.ID, tblOutPoints.Bit_No, tblOutPoints.Bank_No " & _
"FROM tblOutPoints " & _
"WHERE tblOutPoints.ID = Index;"

' "WHERE tblOutPoints.ID = 2;"

Set DB = OpenDatabase(StoredDataPath)
Set RS = DB.OpenRecordset(strSQL)
MsgBox RS!Time_Msec

------ end code

The second commented Where using a numeral 2 works perfect. Access creates a string as follows: WHERE (((tblOutPoints.ID)="Index"));
however it also fails.

Any suggestions appreciated.

PS: I'm looking for an Access-based SQL syntax checker/corrector that one of the MVPs referred me to a few years back. May have been Douglas Steele.



Replace

"WHERE tblOutPoints.ID = Index;"

with

"WHERE tblOutPoints.ID = " & Index & ";"

HTH
.



Relevant Pages

  • Re: SQL syntax
    ... I'm receiving a 'Too Few Perameters. ... expected 1' error when trying to use a variable in place of a number in a Where statemet of an SQL string. ... I'm looking for an Access-based SQL syntax checker/corrector that one of the MVPs referred me to a few years back. ...
    (microsoft.public.vb.database)
  • Re: SQL syntax
    ... I'm receiving a 'Too Few Perameters. ... a variable in place of a number in a Where statemet of an SQL string. ...
    (microsoft.public.vb.database)
  • SQL syntax
    ... I'm receiving a 'Too Few Perameters. ... variable in place of a number in a Where statemet of an SQL string. ... I'm looking for an Access-based SQL syntax checker/corrector that one ...
    (microsoft.public.vb.database)