Results 1 to 3 of 3
  1. #1
    Sulldog is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2012
    Posts
    1

    Query Criteria based on a text box of multiple comma seperated values


    I need to run a query to return data on multiple customer numbers. I have a form with a text box. The query's criteria is based on the text.
    If I manually input the criteria in the query as Customer_Num in(100,200,300) it works. When I input 100,200,300 in the text box of the form, the query (Customer_num in([Forms]![frm_Main]![txtCustomer#])) it returns no rows.

    Thanks in advance for your help!

  2. #2
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    It doesn't quite work that way, sadly. At least, it hasn't for me. What I do is take the SQL from the query and create a string variable in VBA while leaving room for another variable in your IN() statement. For example:
    strWHERE = Me.txtCustomer#
    strSQL = "SELECT stuff1, stuff2 INTO anotherTable FROM someTable WHERE stuff2 In(" & strWHERE & ");"
    Then you can DoCmd.RunSQL(strSQL) to get your query going.

    On a sidenote, I'd get rid of the # from the text box name. Could lead to issues.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    That's because the value entered into textbox is really just one continuous string, not a set of discrete values.

    Shabz, I am somewhat baffled that you have success with the code you describe.

    Yes, should avoid spaces, special characters, punctuation (underscore is exception) in names, also reserved words as names. Better would be txtCustomerNum.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 9
    Last Post: 03-30-2012, 09:22 AM
  2. Replies: 10
    Last Post: 07-02-2011, 11:51 AM
  3. Displaying multiple text values in crosstab query
    By MFlood7356 in forum Queries
    Replies: 6
    Last Post: 06-28-2011, 11:30 AM
  4. Replies: 0
    Last Post: 04-08-2010, 12:22 PM
  5. Replies: 10
    Last Post: 02-06-2010, 10:50 PM

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