Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Statement

Status
Not open for further replies.

JDU

Technical User
Dec 23, 2002
182
US
strGetFireSafety = "Select * from tblCompetencyData where txtLogin =" & Chr(34) & rsGetName!txtLogin & Chr(34) _
& "and txtProcedureNo = 'MAN-001'" _
& "and datediff('yyyy', nbtInputBox, nbtEvalDate) = 0"

Set rsGetFireSafety = db.OpenRecordset(strGetFireSafety)

In the above code,I keep getting the error "Too few parameters, expected one". It seems that it is not recognizing the value(date) in the field nbtEvalDate. nbtInputBox is an input box whose value(date) is being recognized. Can someone help me correct this please.

Thanks
 
strGetFireSafety = "Select * from tblCompetencyData where txtLogin =" & Chr(34) & rsGetName!txtLogin & Chr(34) _
& " and txtProcedureNo = 'MAN-001'" _
& " and datediff('yyyy', nbtInputBox, nbtEvalDate) = 0"

Set rsGetFireSafety = db.OpenRecordset(strGetFireSafety)

Added a space before the and

 
It didn't seem to solve the problem
 
Char(34) = "
You are probable looking for '
If so just use ' on the left side of "
Like this...

strGetFireSafety = "Select * from tblCompetencyData where txtLogin = '" & rsGetName!_
& "' and txtProcedureNo = 'MAN-001'" _
& " and datediff('yyyy', nbtInputBox, nbtEvalDate) = 0"


 
This is what I have.

strGetFireSafety = "Select * from tblCompetencyData where txtLogin = " & Chr(34) & rsGetName!txtLogin & Chr(34) _
& " and txtProcedureNo = 'MAN-001'" _
& " and datediff('yyyy', nbtInputBox, nbtEvalDate) = 0"

I know that the problem is in the last line because if I comment it out, I don't get an error.
 


strGetFireSafety = "Select * from tblCompetencyData where txtLogin =" & Chr(34) & rsGetName!txtLogin & Chr(34) _
& "and txtProcedureNo = 'MAN-001'" _
& "and datediff('yyyy', nbtInputBox, nbtEvalDate) = 0"

PUT A STOP OR CONTROL BREAK HERE, GO TO THE IMMEDIATE WINDOW, TYPE ?strGetFireSafety, REPLY BACK AFTER CUTING AND PASTING RESULTS OF ? IN A REPLY WINDOW

Set rsGetFireSafety = db.OpenRecordset(strGetFireSafety)
 
Here you go:

?strGetFireSafety
Select * from tblCompetencyData where txtLogin = "CB415" and txtProcedureNo = 'MAN-001' and datediff('yyyy',nbtInputBox,nbtEvalDate) = 0
 
Your variables nbtInputBox,nbtEvalDate are being interperted as part of the string

Make sure your variables nbtInputBox,nbtEvalDate are formated as dates.

SELECT tblCompetencyData.txtLogin, tblCompetencyData.txtProcedureNo," +((DateDiff("yyyy",nbtInputBox,nbtEvalDate))+" AS Expr1, *
FROM tblCompetencyData
WHERE (((tblCompetencyData.txtLogin)='CB415') AND ((tblCompetencyData.txtProcedureNo)='MAN-001') AND ((0)=0));


Why are you using Chr(34) ? If you are trying to process a string within a string use a single quote within a double. Sql sees the single quote as if it were a double quote. If you actually have passwords that are literally "CB415" yours is correct.

 
There is a typo in what I sent you; fixed here:

SELECT tblCompetencyData.txtLogin, tblCompetencyData.txtProcedureNo," +((DateDiff("yyyy",nbtInputBox,nbtEvalDate))+" AS Expr1, *
FROM tblCompetencyData
WHERE (((tblCompetencyData.txtLogin)='CB415') AND ((tblCompetencyData.txtProcedureNo)='MAN-001')

typo
AND ((0)=0));
should be
AND ((Expr1)=0));

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top