Results 1 to 5 of 5
  1. #1
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53

    Like Criteria from atext box.

    I have a form where I am hoping that i can type in keywords into a text box which will then run a query that finds these key words from the data field.



    For example: The user types "car license" into the text box, the query will then search the descriptions field and displays all descriptions that contain "car license" i.e "I have my car license" but not "I have a car and i have a license".

    So far i have tried setting the Criteria using the Like command to pull the value entered in the text box. I tried including the asterixs so that the text can be contained any where within the description.
    Criteria: Like "*[Forms]![Applicants]![KeywordTextbox]*"

    Is this possible and am i on the right track, What should my Criteria be? Cheers.

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    your code does not appear tobe correct, it should be

    Like "*" & [Forms]![Applicants]![KeywordTextbox] & "*"

    but to answer your question, train your users to use the *

    so if they want to find records which have both car and license in it (in that order), tell them to type 'car*license'

    if you want individual searches so it will also find 'I have a license and i have a car' then you will need some code to break the string down into individual components and build a more complex criteria

    Be aware that putting a * at the beginning of your search string forces Access to do a sequential search which is significantly slower than one on an indexed field. For relatively small data volumes it is not a really problem but as your db grows you will see performance suffer.

    I'm not saying never code the initial * but use it wisely. I train my users to use it themselves when required so I do not include *'s in my code. Typically they are searching for a name so looking for 'smith' they will start with a 's' anyway, all an initial * would do is slow it down.

  3. #3
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    Sorry im not sure i explained myself fully let me use a better example closer to what im trying to do.

    Item Description in the table is: Lanterns - 200 mm diameter 4 aspect LED lanterns.

    The user wants to search for this so tries typing in a keyword that is contained within the description. i.e "4 aspect LED". The query will then show all the item descriptions that contains 4 aspect LED from any part of the description.

    I didnt understand what you meant by train your users to use the *?

  4. #4
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    Item Description in the table is: Lanterns - 200 mm diameter 4 aspect LED lanterns.

    The user wants to search for this so tries typing in a keyword that is contained within the description. i.e "4 aspect LED". The query will then show all the item descriptions that contains 4 aspect LED from any part of the description.
    then the correction to your criteria should do the trick

    Like "*" & [Forms]![Applicants]![KeywordTextbox] & "*"

    I didnt understand what you meant by train your users to use the *?
    For your purposes it probably doesn't matter. training them to use it means they could also find 'Lanterns....LED'

  5. #5
    Torinjr is offline Advanced Beginner
    Windows 7 32bit Access 2013
    Join Date
    May 2015
    Posts
    53
    Hi Ajax thanks for the correction. That was all i needed. And i understand what you mean now.
    Cheers

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

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 12:45 PM
  2. Replies: 1
    Last Post: 11-13-2014, 11:34 PM
  3. Replies: 4
    Last Post: 08-30-2014, 10:23 AM
  4. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  5. Replies: 5
    Last Post: 08-02-2012, 09:44 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