Find a key word based on a list of characters(sentence)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rvinodk
    New Member
    • Jan 2010
    • 3

    Find a key word based on a list of characters(sentence)

    Is it possible to search for a particular word in a string of words
    For Eg

    I am Crazy :))
    Its a Crazy world
    It is a lovely day.

    If I input Crazy in a form, It should list the first 2 sentence.
    Could anyone give me a code to achieve this?
    Thanks in Advance
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    One way is something like

    [code=sql]
    SELECT WordStringField
    FROM TheTable
    WHERE WordStringField like "%" & Forms!YourForm. SearchTextbox & "%"
    [/code]

    I haven't tested that so you might need to adjust the syntax.
    You will definitely need to adjust the names to suit your own.
    Put it into a query and put a button on the form that opens the query.
    Or some other method of getting the result.

    Comment

    • rvinodk
      New Member
      • Jan 2010
      • 3

      #3
      Hi,
      Thanks for getting back to me.
      I have a AuthorsDatabase with Fields AuthorName and Quotes(Text Field)
      I created a Form Called QiuoteSelection Q
      with a Outbound Field Called QuoteQ where I will input the word

      I have a list box called KeywordSelectio n
      with the Query SELECT Quotes FROM AuthorsDatabase WHERE Quotes like "%" & Forms!QuoteSele ctionQ.QuoteQ & "%";

      It does not work . Please Help

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        I will try and put together a mock up of what you are doing and Post something more specific for you later.

        In the meantime...some thing for you to consider
        Maybe you can find the answer before I post back.
        You will gain the most experience for yourself if you can.


        Where have you put the query?
        You input something into QuoteQ...Then what?
        What I mean by that is
        How are you causing the query to execute after something new gets entered?

        Do you have VBA code in the after update event or the key down event or some other event, of the QuoteQ textbox, that takes note that a new search text has been entered so I had better refresh the list box?


        I would suggest that you
        1) create a query using the sql.
        ....That way you can test the query by itself and adjust it until it works.
        ....If you open the query without the form being open then the query
        ....will ask you to supply the parameter via an input box.
        ....Once the query itself is working then
        2) Put a button on your form that opens the query.
        ....Run the form enter something into the textbox and click the button
        ....That way you can test that the query is bound to the textbox correctly.
        ....Once that is working then
        3) Either bind your Listbox to the query
        ....or paste the SQL from the query into the source property of the list box.
        ....Now all you need to do is cause the listbox to refresh itself at the appropriate time. Probably something like Me.Requery or Me.Refresh in the after update event of the QuoteQ textbox


        You should, as a Newbie, always build up the workings of your forms in a progressive way, as described. Too many changes at the same time can become confusing to debug when it doesn't work.

        I still, as a so called "expert", still break something that doesn't work down into simpler steps and progressively build it up into what I need. Its just easier to discover where something is going wrong when you do that. Of course, as you gain experience you need to do that less and less and the simple can become more and more complex.

        Comment

        • Delerna
          Recognized Expert Top Contributor
          • Jan 2008
          • 1134

          #5
          Actually I have just discovered the first thing
          In the query, the % should be *.

          I write SQL both in "MS access" and "MS SQL Server" but mostly "MS SQL Server"
          SQL sytax varies slightly between those two database apps and I gave you the SQLSever syntax.

          My bad, and I appologies for that.

          Comment

          Working...