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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

continuus search 1

Status
Not open for further replies.

and0b

MIS
Mar 27, 2007
51
US
Hi!

I need some help with small search function. I have a from on which I want to have a textbox in which user will type characters of last name of the personal record in the table. How to make this search so it will show in listbox below only records filtered by typed characters?
For ex. when user will type and listbox will show all names starting with and like andara, andabaca, andbara, andrews........

Thanks for any help!
 
If you want this to happen as the user is typing in the text box, you can set the text box On Change event to something like:
Code:
Dim strSQL as String
strSQL = "SELECT FieldA FROM tblNoName WHERE FieldMaybeA Like """ & Me.txtBoxNoName.Text & "*"" ORDER BY FieldA;"
Me.[listbox below with no name].RowSource = strSQL

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Thanks for quick answer, but it does not work.
Here is my code, wot is wrong?


Private Sub List2_AfterUpdate()
Me.List2.Requery
End Sub

Private Sub Text0_Change()
Dim strSQL As String
strSQL = "SELECT CompanyName FROM customer WHERE CompanyName Like " & " * " & Me.Text0.Text & " * " & " ORDER BY CompanyName"
Me.[List2].RowSource = strSQL
End Sub
 
it does not work" does not work for me. You haven't implemented my suggestion. You are missing quotes and have extra spaces that shouldn't be there.

I just created a form with a text box named txtSearch and a list box named lboFound. This code worked exactly as expected
Code:
Private Sub txtSearch_Change()
    Dim strSQL As String
    strSQL = "SELECT CompanyName FROM Customers " & _
        "WHERE CompanyName like ""*" & _
        Me.txtSearch.Text & "*"" ORDER BY CompanyName"
    Me.lboFound.RowSource = strSQL
End Sub

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
I did this same and in the lboFound it shows:

SELECT CompanyName FROM Customers WHERE CompanyName like "*b*" ORDER BY CompanyName

I did copy and paste your code.
Andrew
 
Make sure your Row Source type is Table/Query.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top