Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Search text box 1

Status
Not open for further replies.

splats

Technical User
Jan 2, 2003
131
0
0
Hello

In a perfect world I want to create a Search text box that... searches to see if the word input into the text box can be found in one of three fields (Category, ResourceItem, ResourceSpecifics)

I would like the search to include all incidents of that word for example

If I enter in "water"

I will get back all records like
"waters"
"stillwater"
"blue water slide"

etc..

The search will look in all fields (Category, ResourceItem, ResourceSpecifics)for these records that match.

Would you please point me in the right direction on how to build this wonder search textbox?

thankyou
 
This may not work completely how you want it to, but it may provide a good start.

I set up a text box to type a keyword (txtFind) and a listbox to return records with this keyword (lstQuery). The following is the vb code.

******************Code Starts Here******************
Private Sub txtFind_AfterUpdate()

With Me.lstQuery
.RowSource = _
"SELECT * FROM TableName " & _
"WHERE FieldName LIKE " & Chr(34) & Me.txtFind & Chr(34)
.Requery
End With

End Sub

******************Code Ends Here*******************

The user can type “*Water*” in to the text box and the list box will query records that contain “water”. The asterisk is considered a wildcard. I have not figured out how to get the asterisks into the vb code so that the user does not have to type the them, but I’m sure with a little effort it can be done. Type “Wildcards” into the help menu for more information on them.

I hope this helped,
John
 
Hello there!

This is what I have tried so far. Unfortunately, I am getting a type mismatch error.

Private Sub txtSearch_AfterUpdate()

Dim stDocName As String
Dim txtFind As String

txtFind = Me.txtSearch
stDocName = "QU-CompleteResources"

With Me.List101
.RowSource = _
"SELECT * FROM stDocName " & _
"WHERE CompleteResources " Like "'%' + txtFind + '%'" Or "txtFind + '%'" Or "'%' + txtFind" Or txtFind
.Requery
End With

End Sub


Any suggestions would be greatly appreciated.

Thank you
 
Hi Steve. I’m not sure about a couple things in your code. First, where you have “stDocName” should be your table name. Is that “QU-CompleteResourses”? I’m not sure about this, but I wouldn’t Dim it. Second, I’m not familiar with the “%”. It may be ok, but I normally use Chr(34)?

Perhaps you know something that I don’t know and I should let someone else help you on this one, but I’ll give you my version of how I would do it.

*****************Code Starts Here*******************
Private Sub txtSearch_AfterUpdate()

With Me.List101
.RowSource = _
"SELECT * FROM QU-CompleteResources " & _
"WHERE CompleteResources LIKE " & Chr(34) & Me.txtSearch & Chr(34)
.Requery
End With

End Sub
*****************Code Ends Here********************
I know that you want to query a few fields, but I would start with one to get it working first (CompleteResourses).

Remember, the user must type an asterisk before and after the keyword with the way the code above is written. If you or someone else can figure out how to imbed it in the vb, please post it to this thread.

Let me know if I’m getting in the way,
John
 
As another alternative, you can insert the following into a query for a parameter prompt:

Like "*" & [Enter Keyword to Search For] & "*"

 
Hello everyone

thank you for your input!

I think that I have found a solution to my question. Instead of the text box, I have created a query concatenating three fields. The query uses:

Like "*" & [Enter Keyword to Search For] & "*"
for the criteria.

I then created a form for this query.
On my welcome form, I have created a command button that opens the form for the query.
A message box appear asking for (enter keyword to search).

It works great!

Of course, I would like to tweak it.

Again, in a perfect world, I would like the title bar or the Parameter (message box) to be retitled (instead of Enter Parameter Value. Does anyone know how I can do this?

TIA [bigcheeks]

Tina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top