Results 1 to 4 of 4

Thread: searching with sql using variables..

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168

    Post

    Hello, from reading some posts earlier I came up with this code to use sql to retrieve records. Please tell me what I am doing wrong.

    rs.open "Select * From Table1 Where Number = '%" & MyVar1 & "%", ConnectString, adOpenStatic, adLockOptimistic

    The MyVar1 is a is a numeric value since the Number field is a numeric value. It does not work however, can someone please help.

    Thanks,
    Thai

  2. #2
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284

    Post

    It's hard to say based purely on what you have shown, but I presume you are opening a connection before you attempt to open the recordset. Other than that I see no need for the percentage signs. If that doesn't try using an error handler to trap the specific error you are getting.

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    Try:

    rs.open "Select * From Table1 Where Number = " & MyVar1, ConnectString, adOpenStatic, adLockOptimistic


    Pattern matching isn't used with the equal operator ('='), it's used with the like operator ('like'). The other thing wrong with your statement is you have a single quote that has no matching single quote.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Posts
    168

    Post thanks

    that worked, thanks

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