Advanced search

jeudi 16 avril 2015

Hello all,



Relatively inexperienced Access/VBA user here. I have a data set consisting of many fields, many of which contain long-text. I am interested in making a split form with a search tool that will search by two keywords. The first keyword will be entered into a text-box, a search button clicked, and a query is revealed in where the criteria is met. So if I was to search the word "Kate", every row with a field that holds the word "Kate" is shown in the query.



Then, in a second text box, I want to be able to enter another word, and filter the query results by the word entered. So after searching the word "Kate" and clicking the search button, a query is executed and shown. Then, I enter the word "Sparrow", and from the first query, a second query is executed- this time, only rows with the words "Kate" and "Sparrow" are revealed.



I've managed to write the code for the first text box and it works fine. If I was to look up the word "kate" it would generate a query that matched that criteria perfectly. Writing a code for the 2nd text box, one that generate a further filtered query, is beyond me. Below is the code for the first box. I've been trying to develop the second text box search based on it, but to no avail.








Code:



Private Sub search_Click()

Dim searchbutton As String

Dim searchtext As String

searchtext= Me.keyword.Value

searchbutton = "SELECT * from table where ((c1 like ""*" & searchtext & "*"")or (c2 like ""*" & searchtext & "*""))"

Me.RecordSource = searchbutton

End Sub



note* - there are quite a few more fields in the real code, but for the sake of space I omitted them here.

Any suggestions?

Advanced search

0 commentaires:

Enregistrer un commentaire

Labels