473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Search by Multiple Keywords from a text field

Dear Sir
I've a table called "Table3" with primary key and questions
--------------------
P.K | Question
--------------------
I'd like to search in the questions field using multiple keywords that are not related,
i.e., "population, crowd, ...etc".
My form contains:Text Box(txtDescription), search button(cmdMultiSearch).

I read the post "Search by Multiple Keywords "
and in similar fashon I modified the code to:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdMultiSearch_Click()
  2.      Dim intIdx As Integer
  3.      Dim strWork As String, strSearch As String
  4.      Dim GCriteria As String    'Unnecessary if Dimensioned elsewhere
  5.  
  6.      If Nz(txtDescription, "") = "" Then
  7.          MsgBox "You must enter a search string."
  8.      Else
  9.          'Generate search criteria
  10.          GCriteria = ""
  11.          strSearch = txtDescription  'txtSearchString
  12.          Do
  13.              intIdx = InStr(1, strSearch, ",")
  14.              If intIdx > 0 Then
  15.                  strWork = Trim(Left(strSearch, intIdx - 1))
  16.                  strSearch = Mid(strSearch, intIdx + 1)
  17.              Else
  18.                  strWork = Trim(strSearch)
  19.                  strSearch = ""
  20.              End If
  21.              GCriteria = GCriteria & " AND ([" & Question & _
  22.                          "] Like '*" & strWork & "*')"
  23.  
  24.          Loop While strSearch > ""
  25.          GCriteria = Mid(GCriteria, 6)
  26.  
  27.          With Me   'Assuming Me = Form_frmReferenceBooks otherwise With Form_frmReferenceBooks
  28.              'Filter frmReferenceBooks based on search criteria
  29.              .RecordSource = "SELECT * " & _
  30.                              "FROM Table3 " & _
  31.                              "WHERE " & GCriteria
  32.              .Caption = "Table3 (" & _
  33.                         Question & _
  34.                         " contains '" & _
  35.                         txtSearchString & "')"
  36.          End With
  37.          MsgBox "Results have been filtered."
  38.      End If
  39. End Sub
I get the message"Results have been filtered.".
My question is how to get the search result in a table???
Thanks for help.
Sep 1 '14 #1

✓ answered by NeoPa

Hi.

I'd be happy to help further but a more detailed answer requires a much more detailed question.

For instance, which table would you like the data output to? Have you considered how you will use this table? If it's a multi-user situation this is much more involved.

In very basic terms you need SQL of the format :
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [DestinationTable]
  2.           ( [Field1]
  3.           , [Field2] )
  4. SELECT      [Field1]
  5.           , [Field2]
  6. FROM        [SourceTable]
  7. WHERE       ({YourCriteria})

9 4368
NeoPa
32,556 Expert Mod 16PB
To get the results into a table you need to execute a query very similar to what you have already, but as an append (INSERT INTO) query.
Sep 1 '14 #2
Sorry But how to do that because I am new to Access?
Sep 1 '14 #3
NeoPa
32,556 Expert Mod 16PB
Hi.

I'd be happy to help further but a more detailed answer requires a much more detailed question.

For instance, which table would you like the data output to? Have you considered how you will use this table? If it's a multi-user situation this is much more involved.

In very basic terms you need SQL of the format :
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [DestinationTable]
  2.           ( [Field1]
  3.           , [Field2] )
  4. SELECT      [Field1]
  5.           , [Field2]
  6. FROM        [SourceTable]
  7. WHERE       ({YourCriteria})
Sep 1 '14 #4
Thanks Sir;
It is not multi-user, I did exactly what you advised me but every run I get the whole DB in the DestinationTable.
So is the query syntax wrong or what?
Thanks in advance.
Sep 2 '14 #5
NeoPa
32,556 Expert Mod 16PB
From what you say it sounds like the {Criteria} itself is wrong. It would be a good idea, at this stage, to post your SQL (<>VBA) code for us to look over for you.
Sep 2 '14 #6
Sorry I mean my SQL statement.
My SQL is:
Expand|Select|Wrap|Line Numbers
  1. SELECT Table3.Question, Table3.ID
  2. FROM Table3
  3. WHERE (((Table3.Question) Like  "*"& [Forms]![Main]![txtDescription] & "[!a-z]*"));
but I wand to search for multiple words from the text box and get the result in a table as I click the command button.
Thanks
Sep 3 '14 #7
NeoPa
32,556 Expert Mod 16PB
SQL / Query - Both are understood to be the same. I was simply suggesting you avoid posting the VBA code that creates your SQL as many members (unfortunately) do in circumstances where that is not appropriate. You have posted the SQL perfectly (Use the [CODE] tags for preference but the contents are fine).

Back to your questions :
The first problem is that there are two fundamental questions in the question. This is not how things are supposed to work. One question per thread is the rule.

However, in this case there is one fairly simple one which we will get out of the way and allow the thread to remain about matching multiple keywords.

Changing a simple SELECT query into an append (INSERT INTO) query is done by adding the INSERT INTO clause at the front. As illustrated in my (amended) post #4. The INSERT INTO clause should include a list of the fields to take the data within parentheses.

As for the criteria used to handle multiple words, that is much more of a question and will require us to update the SQL code in VBA and execute the amended SQL code from the VBA string. Before we get that far though, we need to find out why what you have isn't working as expected.

First try for me to update the SQL so that each ampersand (&) character is surrounded by at least one space. Test the results with a known value in txtDescription and report back the results and the value used.
Sep 3 '14 #8
Thanks Sir, it works fine.
Sep 5 '14 #9
NeoPa
32,556 Expert Mod 16PB
Good to hear :-)

Was it the ampersand?
Sep 5 '14 #10

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

Similar topics

6
by: Rizyak | last post by:
******************** alt.php.sql,comp databases.ms-sqlserver microsoft.public.sqlserver.programming *********************************** Why doesn't this work: SELECT * FROM 'Events'
4
by: Abbey Krystowiak | last post by:
Does anyone know if I can have a field in a row where I can add two lines of info without adding a whole new line? and then there would be a drop down menu? *** Sent via Developersdex...
5
by: JP SIngh | last post by:
Hi All This is a complicated one, not for the faint hearted :) :) :) Please help if you can how to achieve this search. We have a freetext search entry box to allow users to search the...
1
by: Sheau Wei | last post by:
i want to make a search engine for may database. i want to make the radio option at the search engine, but how to handle the search at the radio and the text field
3
by: Richard S | last post by:
CODE: ASP.NET with C# DATABASE: ACCES alright, im having a problem, probably a small thing, but i cant figure out, nor find it in any other post, or on the internet realy (probably cuz i wouldnt...
3
by: sachin pathare | last post by:
hi all, plz help me out, is there any function or wayout to find multiple keywords from a perticular string stored in the database. e.g String stored in database: "hi my name is sachin"...
5
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the...
6
by: martin DH | last post by:
Hello all, I'm thinking this is a simple question... I have a table (tblData) that includes a large-capacity text field (255 characters). I would like to write a query that pulls records that...
3
by: dugald.morrow | last post by:
I have some javascript that updates the text in a text field after certain actions take place such as clicking a checkbox. The javascript works fine in Safari and Firefox, but in IE, the text in...
2
by: John Kotuby | last post by:
Hi all, Maybe this belongs in the Full Text group but I am writing an ASP.NET application with a SQL Server 2005 backend, so I am posing the question here. I have been using fulltext search...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.