Results 1 to 3 of 3

Thread: Problem with WHERE clause & Access db

  1. #1
    Guest

    Red face

    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.

  2. #2
    Guest

    Got it

    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)

  3. #3
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Columbia, SC USA
    Posts
    374
    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:
    Code:
    dim workint as integer 
    workint = 3 
    
    Set rs = db.OpenRecordset("SELECT * FROM Street " _ 
    & "WHERE (street.Provincia_ID = " & workint & )")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width