Search texbox

  • Thread starter Thread starter Cesar Zapata
  • Start date Start date
C

Cesar Zapata

Hello,

First of all thanks for taking your time reading this..
I have a form with 2 controls... 1 listbox and texbox. What i'm trying to
do is to change the rowsource of the lisbox from the textbox to show me only
the names in the textbox but when I apply the code below it does not work...
not errors the list just stays blank.




Private Sub TXTSEARCH_AfterUpdate()
Dim strSQL As String

If Not IsNull(Me![TXTSEARCH]) Then

strSQL = "SELECT TblCustomer.Last Name, TblCustomer.First
Name,TblCustomer.CustormerID FROM TblCustomer WHERE TblCustomer.Last Name
Like " & Me.TXTSEARCH.Value & """*"""

Me.ListName.RowSource = strSQL
Me.ListName.SetFocus
Else
strSQL = ""
Me.ListName.RowSource = strSQL
Me.ListName.SetFocus

End If
End Sub


Thanks,
CZ
 
I read a post by a MVP long ago (sorry, I forget who) that said "DO NOT use
spaces in field names. You will only have problems!".

Since you used spaces in your field names, you must use brackets around
field names with spaces in them.

Try this first without the Where clause to see if records are being found:

strSQL = "SELECT TblCustomer.[Last Name], TblCustomer.[First
Name],TblCustomer.CustormerID FROM TblCustomer

If that works, add the Where clause.
Or you could try the message box to see what the string looks like:

strSQL = "SELECT TblCustomer.[Last Name], TblCustomer.[First
Name],TblCustomer.CustormerID FROM TblCustomer WHERE TblCustomer.[Last Name]
Like " & Me.TXTSEARCH.Value & """*"""

MsgBox strSQL ' << used to debug - comment out or delete later
Me.ListName.RowSource = strSQL

Also, I think that you might need to add two double quotes after 'Like'.
the message box should show you if the string is right.

HTH
Steve
 
Back
Top