Results 1 to 6 of 6
  1. #1
    jammerdk is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Location
    Denmark
    Posts
    2

    Question one unbound textfield with seperating commas into multiple criteria

    Hi guys

    I would like to turn in my unbound form field when seperated with commas into a multiple search criteria.

    I've almost done this succesfully with the following code

    SELECT *
    FROM tbl1
    WHERE (((InStr("," & Forms!frmTest!txtFruit & ",","," & [Fruit] & ","))>0));

    However using this code the user have to type in the exact string.



    ex.

    Textfield : Apple,Banana

    Returns.....

    Apple
    Banana

    Instead would I like the user being able to throw in a wildcard symbol

    ex.

    Textfield : *pl,Ba*

    Returns.....

    Apple
    Banana

    Any ideas to solve this problem?

  2. #2
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Drop your textbox data into an Array using the split() function. Then you can do a foreach loop through your array, then in your query use the Like expression. Insert your results into a results table and then use that results table to make your form.

    Code:
    Dim strSearch() as string
    Dim item as variant
    
    strSearch = split(Forms!frmTest!txtFruit)
    currentdb.execute "DELETE * FROM tblResults"
    
    Foreach item In strSearch 
      currentdb.execute "INSERT INTO tblResults SELECT * FROM tbl1 WHERE Fruit LIKE '" & item & "'" 
    Next
    Last edited by Xipooo; 02-13-2014 at 05:25 PM. Reason: Added code.

  3. #3
    jammerdk is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Feb 2014
    Location
    Denmark
    Posts
    2
    Might mention my tables where my quieries gather information from only are linked.

    I'd tried your proposal though and with the minor tweaks (split clause and currentdb.execute) and it did work, but I would like is a solution within the query itself. (rather not add tables)

  4. #4
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Yeah, here's a faster way to skin the cat and do what you want. Dunno why I didn't think if it first actually.

    Code:
    dim strSQL as string
    dim strFruits() a string
    dim x as integer
    strFruits = split(Forms!frmTest!txtFruit)
    strSQL = "SELECT * FROM tbl1"
    
    for x = 0 to ubound(strFruits)
       if x = 0 then 
        strSQL = strSQL & " WHERE Fruit Like '" & strFruits(x) & "'"
       else
        strSQL = strSQL & " OR Fruit Like '" & strFruits(x) & "'"
       end if
    next x
    currentdb.querydefs("<queryname>").SQL = strSQL

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Here's a small database based on Xipoo's response.
    Created with 2010 saved as mdb

    Open the form, enter your search terms in text box and clickToSearch
    If you don't use a search term, you get all records.

    Good luck
    Attached Files Attached Files

  6. #6
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Quote Originally Posted by orange View Post
    Here's a small database based on Xipoo's response.
    Created with 2010 saved as mdb

    Open the form, enter your search terms in text box and clickToSearch
    If you don't use a search term, you get all records.

    Good luck
    Thanks for putting that together Orange.

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

Similar Threads

  1. Unbound Combobox Filter By Date Criteria
    By burrina in forum Forms
    Replies: 8
    Last Post: 01-04-2013, 02:24 PM
  2. DLookup with textfield in criteria
    By smeghead67 in forum Programming
    Replies: 4
    Last Post: 08-07-2012, 12:18 PM
  3. Seperating data on reports
    By tarhim47 in forum Reports
    Replies: 6
    Last Post: 07-19-2011, 10:53 AM
  4. Commas in CSV file
    By cotri in forum Forms
    Replies: 7
    Last Post: 01-28-2010, 03:53 PM
  5. Commas in a Combo
    By DJFayo in forum Forms
    Replies: 0
    Last Post: 10-18-2006, 12:13 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