View Full Version : User-Input Keyword text search


LouRecine
03-08-2001, 01:42 PM
Try as I might, I cannot figure out how to create a command button on a form (would be based on a query, I suppose) that will prompt the user to enter a text value (like they would in a "keyword search") and then, every instance of that word in every field, would be returned to the User. I've tried offering this with Access' "Find" function, and it works okay most of the time, but sometimes hangs up. I have Access 2000, and am running under Windows 98. I will be thrilled to get any advice!
Lou Recine

Mendel8
03-08-2001, 03:38 PM
If I'm reading this right then you could do something like this:

Create the button and set the On_Click property to "event procedure" and in the form code write something like this:

Private Sub cmdFindWord()

Dim dbs as Database
Set dbs = CurrentDb

Dim FindWord As String
Dim i As Integer
Dim recQuery as RecordSet
Set recQuery = dbs.OpenRecordSet("SELECT * FROM Query")

FindWord = txtFindWord.Text

Do While Not Query.EOF
For i = 1 To NumberofFields
If InStr(recQuery.Field(i), FindWord) Then
.
. 'Do whatever you want like
. 'output result to a table.
End If
Next i
Loop


This is kinda sloppy and some people will argue that code like this shouldn't be put into the form code(in which case they are right), but it can be a quick and easy solution. HTH