PDA

Click to See Complete Forum and Search --> : Problem with WHERE clause & Access db


Sep 11th, 2000, 05:36 PM
This is driving me mad. I am new to VB and I am sure that this is something very simple. Please tell me why the code example 1 works and code example 2 does not when they ought to be doing the same thing.

----------------------------
This works:

Set rs = db.OpenRecordset("SELECT * FROM Street " _
& "WHERE (street.Provincia_ID = 3)")


-----------------------------
This gives run time error 3061 ("Too few parameters. Expected 1"):

dim workint as integer
workint = 3

Set rs = db.OpenRecordset("SELECT * FROM Street " _
& "WHERE (street.Provincia_ID = workint)")

----------------------------
As you can see, the only difference is that instead of the number 3 I am using a variable workint which I had set to 3 previously.

street.provincia_ID is defined as integer in the database.

Please help, is there any syntax problem or something.

Sep 11th, 2000, 06:05 PM
Got it.. I had to do the following:

'Set up the SQL string
SQLString = "SELECT * from Street WHERE Provincia_ID = " & workint

'Get the data
Set rs = db.OpenRecordset(SQLString)

DrewDog_21
Sep 12th, 2000, 10:34 AM
Glad you fixed the problem. Your error was one of simple
syntaxt, though. Your variable workint should come outside
of the quotes of the SQL statement, like this:

dim workint as integer
workint = 3

Set rs = db.OpenRecordset("SELECT * FROM Street " _
& "WHERE (street.Provincia_ID = " & workint & )")