Results 1 to 4 of 4
  1. #1
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47

    Exclamation Why this sql RecordSource not working?

    Hi all,
    I have this table named inv

    ID code qty
    1
    [1[2[26
    2[1[3[29
    3[1[4[ 33
    4[1[5[ 28
    5[1[6[ 30
    6 [1[7[ 18


    7 [1[8[ 20
    8 [1[9[ 9

    and i use this code to put the 2 records on a form
    nostr = "[2[8[1[8[1[7["
    Me.RecordSource = "SELECT * FROM inv WHERE ((InStr('" & nostr & "', qty)) > 0);"

    The only 2 records should show are with ID 6 and 7 because only they have the code that found in nostr, but nothing show up, any idea?

    Here's the db if you want to try it out, thanks.
    Last edited by zx3; 08-28-2011 at 08:25 PM.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Code:
        Me.RecordSource = "SELECT * FROM inv WHERE ((InStr('" & nostr & "', qty)) > 0);"
    this is your existing statement in the ON CLICK event of your button

    you're checking a numeric value (quantity) against a string, that will always fail.

    you want this:
    Code:
        Me.RecordSource = "SELECT * FROM inv WHERE ((InStr('" & nostr & "', code)) > 0);"

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    From VBA Help:

    InStr([start, ]string1, string2[, compare])
    string1 Required. String expression being searched.
    string2 Required. String expression sought.

    I believe you also have your string references reversed.

  4. #4
    zx3 is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Aug 2011
    Posts
    47
    Quote Originally Posted by rpeare View Post
    Code:
        Me.RecordSource = "SELECT * FROM inv WHERE ((InStr('" & nostr & "', qty)) > 0);"
    this is your existing statement in the ON CLICK event of your button

    you're checking a numeric value (quantity) against a string, that will always fail.

    you want this:
    Code:
        Me.RecordSource = "SELECT * FROM inv WHERE ((InStr('" & nostr & "', code)) > 0);"
    Thanks rpeare, i double checked my code, yeah it should be code instead of qty in the sql recordsource string. Thanks for all the time for helping.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-06-2011, 01:24 PM
  2. RecordSource help
    By mann2x in forum Access
    Replies: 3
    Last Post: 10-05-2010, 06:44 PM
  3. Replies: 2
    Last Post: 10-16-2009, 02:47 PM
  4. Recordsource with Multiple queries
    By darshita in forum Programming
    Replies: 1
    Last Post: 08-10-2009, 03:17 PM
  5. update recordsource of subform
    By AndyKim in forum Forms
    Replies: 1
    Last Post: 06-16-2009, 09:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums