Results 1 to 10 of 10

Thread: SQL search with integer variable

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Mexico
    Posts
    16

    Question 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...

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    If it's a string value it must have quotes around it...
    VB Code:
    1. Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = 'fol';", dbOpenDynaset)

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    Sorry, I misread!!...
    try this
    VB Code:
    1. Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = " & fol & ";", dbOpenDynaset)

  4. #4
    TimJ
    Guest
    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)

  5. #5
    TimJ
    Guest
    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)

  6. #6
    TimJ
    Guest
    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)

  7. #7
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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:
    1. Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = " & fol & ";", dbOpenDynaset)
    If that variable contains a string, do this...
    VB Code:
    1. 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:
    1. Set RS = DB.OpenRecordset("SELECT * FROM Detfact WHERE Folio = 8;", dbOpenDynaset)
    To do the same but with strings, do this...
    VB Code:
    1. 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.

  8. #8
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696
    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!

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  10. #10
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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
  •  



Click Here to Expand Forum to Full Width