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

Creating a Keyword Search that filters records in a form

P: 112
Hi All this is my first time post, be gentle.

I am looking at creating a keyword search that searches multiple fields in a Form and then filters records that match the keyword. The Form currently has a button that connects to a Query that run the keyword search in several field and then filters the results. The problem is that I can not do a search within a search, or have multiple words searched in any order. For example there are 20,000 records, I click the button and a Pop Up Box asks me to enter a keyword. I type "blue" as my keyword and it filters me down to 1,000 records. If I want to narrow it down farther I can't because if I click the button again it starts the search from my original 20,000 records. So I either need to be able to search for "blue" then re-search my filter records by "green" or to be able to search for "blue and green" in any order over the multiple fields. I have seen several codes posted in other posts that have elements of what I want this to do but I do not know enough about VB code to put it all together. None of them involved using a Query to do the search like I describe above (Which was built by my predecessor). I do not care if it is run off a Button that opens a Message Box or if it is linked to a Text box in the Footer Bar that you just type the keyword into and hit enter. I also do not care if it is built into a Query or just VB code. Also if the keyword in each record could be highlighted when it has filter the records that would be great as some of the fields are memo and there is a lot of text to look at the find the keyword.

Oct 3 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 3,072
Can you post the code the button is using ?

Oct 6 '07 #2

P: 112
Sure here is the code for the Keyword search button.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Keyword_Search_Click()
  2. On Error GoTo Err_Keyword_Search_Click
  4.     Dim stLinkCriteria As String
  6.     DoCmd.Close acForm, "frmDescription"
  7.     DoCmd.OpenForm "frmDescription", , "qryKeyword3", stLinkCriteria
  10. Exit_Keyword_Search_Click:
  11.     Exit Sub
  13. Err_Keyword_Search_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_Keyword_Search_Click
  17. End Sub
Oct 9 '07 #3

Expert 2.5K+
P: 3,072
The query obviously holds a variable for filtering the records, causing the popup asking you the (single) value.
For multiple values you would need to have multiple fields on the form and construct a strCriteria with the entered values.

An easy solution is to use the right-click popup to perform the filtering for single selections or for multiple "AND" related selections, see my userinstruction for this at:
When you need an "OR" relation, then you can use the "Filter by Form" option allowing you to fill multiple "OR" tabs (see left bottom corner).

When you want to use the strCriteria filtering and start coding, then let me know.

Oct 9 '07 #4

Post your reply

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