|
-
Jun 20th, 2001, 02:06 PM
#1
Thread Starter
Junior Member
SQL search with integer variable
I´m using this statement using an integer variable (fol ) to do the search, but I get this error :
Run-Time error '3061'
too few parameters expected 1.
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = fol", dbOpenDynaset)
Thanks...
-
Jun 20th, 2001, 02:11 PM
#2
PowerPoster
If it's a string value it must have quotes around it...
VB Code:
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = 'fol';", dbOpenDynaset)
-
Jun 20th, 2001, 02:13 PM
#3
PowerPoster
Sorry, I misread!!...
try this
VB Code:
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = " & fol & ";", dbOpenDynaset)
-
Jun 20th, 2001, 03:18 PM
#4
String values don't require ' ' around them
do this
dim strSQL as string
strSQL = "SELECT * FROM Detfact WHERE Folio =" & " " & fol
Set RS = DB.OpenRecordset( strSQL , dbOpenDynaset)
-
Jun 20th, 2001, 03:22 PM
#5
The prior is for integer values only. If it is a string variable then
strSQL = "SELECT * FROM Detfact WHERE Folio =" & " " & "'" fol & "'"
Set RS = DB.OpenRecordset( strSQL, dbOpenDynaset)
-
Jun 20th, 2001, 03:31 PM
#6
Correction, I missed an &
The prior is for integer values only. If it is a string variable then
strSQL = "SELECT * FROM Detfact WHERE Folio =" & " " & "'" & fol & "'"
Set RS = DB.OpenRecordset( strSQL, dbOpenDynaset)
-
Jun 20th, 2001, 04:22 PM
#7
PowerPoster
Originally posted by TimJ
String values don't require ' ' around them
Don't know where you learned that mate but you do need quotes around string values in SQL, otherwise you get the error he described. Not only that but you contradicted yourself by including quotes anyway. I'd also like to point out you can edit posts, rather than making 2 correction posts.
Folio =" & " " & "'" & fol & "'"
What the hell is that?!? It should be Folio = '" & fol & "';". I suggest you learn how to code before slagging me off.
Ignore all the bollocks he just gave you..if you want to get an integer value from a variable into an SQL statement, do this.
VB Code:
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = " & fol & ";", dbOpenDynaset)
If that variable contains a string, do this...
VB Code:
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = '" & fol & "';", dbOpenDynaset)
If you just want a straight SQL statement with no variable interpolation to include a number do this...
VB Code:
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = 8;", dbOpenDynaset)
To do the same but with strings, do this...
VB Code:
Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = 'fol';", dbOpenDynaset)
And lastly, if you want to use Dates, put # instead of ' in all above examples and make sure it is in mm/dd/yy format.
Last edited by chrisjk; Jun 20th, 2001 at 04:46 PM.
-
Jun 20th, 2001, 04:37 PM
#8
Fanatic Member
ROFLMFAO
Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!
-
Jun 20th, 2001, 05:13 PM
#9
Monday Morning Lunatic
Easy now, Chris
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 20th, 2001, 05:21 PM
#10
PowerPoster
Hey, he said I was wrong. If i were, then fine, but I ain't so
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|