How to Create a Search for any words

Sunnylei

Registered User.
Local time
Today, 05:43
Joined
Mar 5, 2011
Messages
87
Hi
I create a stock Management database. Table name is StockManagement. Form name is Stock Managment. In the form, I'm trying to create a search button for searching any words in Descriptions field. Code is as follows,

Code:
Private Sub cmSearch_Click()
 
    Dim LSQL  As String
    Dim LSearchString As String
    If Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
        MsgBox "You must enter a search string."
    Else
        LSearchString = txtSearchString
        'Filter results based on search string
        LSQL = "select * from Stock Management"
        LSQL = LSQL & " where Descriptions LIKE '*" & LSearchString & "*'"
 
        'Clear search string
        txtSearchString = ""
        MsgBox "Results have been filtered.  All Descriptions containing " & LSearchString & "."
         End If
       End Sub

However, it does not work for me. I don't know what is missing from it.
 

Attachments

I have made minor changes to your mdb.

QuerySearch is for showing the results of your Search. The SQL for this query is changed whenever you enter a search string. The query should NOT be deleted.
I moved the Clear of the Search term to another button.
A message will be presented if no records contain the search term.

Good luck with your project

Note: You should do a compact and repair from time to time. Your database was over 1.3 MB, I did C/R and it is now 568K
 

Attachments

I have made minor changes to your mdb.

QuerySearch is for showing the results of your Search. The SQL for this query is changed whenever you enter a search string. The query should NOT be deleted.
I moved the Clear of the Search term to another button.
A message will be presented if no records contain the search term.

Good luck with your project

Note: You should do a compact and repair from time to time. Your database was over 1.3 MB, I did C/R and it is now 568K

Hi
I had looked it. It's good idea to add in a query. Thank you very much!!!:)
 
I have made minor changes to your mdb.

QuerySearch is for showing the results of your Search. The SQL for this query is changed whenever you enter a search string. The query should NOT be deleted.
I moved the Clear of the Search term to another button.
A message will be presented if no records contain the search term.

Good luck with your project

Note: You should do a compact and repair from time to time. Your database was over 1.3 MB, I did C/R and it is now 568K

Hi
I come back again to ask how did you created querySearch for me, Why I cannot create one looks like yours, which shows every field in form view, but in design view only can see 'Descriptions' field. I'm in learning stage, so please let me know how you did it.

Thanks :)
 
It doesn't annoy me. It just seems like a waste of our time when we get asked the same thing (in a different form) over again. You were given solutions that work so all you have to do is disect them into bite size chunks and digest them ;)
 
It doesn't annoy me. It just seems like a waste of our time when we get asked the same thing (in a different form) over again. You were given solutions that work so all you have to do is disect them into bite size chunks and digest them ;)

Sure, it's my problem. I will do it. Thanks! :)
 

Users who are viewing this thread

Back
Top Bottom