By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,183 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

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

P: 3
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
Jan 20 '10 #1
Share this Question
Share on Google+
4 Replies


Delerna
Expert 100+
P: 1,134
One way is something like

Expand|Select|Wrap|Line Numbers
  1. SELECT WordStringField 
  2. FROM TheTable
  3. WHERE WordStringField like "%" & Forms!YourForm.SearchTextbox & "%"
  4.  
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.
Jan 20 '10 #2

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

I have a list box called KeywordSelection
with the Query SELECT Quotes FROM AuthorsDatabase WHERE Quotes like "%" & Forms!QuoteSelectionQ.QuoteQ & "%";

It does not work . Please Help
Jan 20 '10 #3

Delerna
Expert 100+
P: 1,134
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...something 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.
Jan 20 '10 #4

Delerna
Expert 100+
P: 1,134
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.
Jan 20 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.