Link to home
Start Free TrialLog in
Avatar of chestera
chestera

asked on

List box like search

Hi EE

I have the following code that will do a search in a list box

intnum = Me!txtDescrip
Me!lstPart.SetFocus
With Me!lstPart
    For i = 0 To .ListCount - 1
        If .Column(2, i) Like intnum Then
            .Selected(i) = True
            Flag = True
            Exit For
        End If
    Next i
End With

although it has a like statement it will only pick up a name for example if the name search is in full ie Smith. I would like to modify or another methode to do a search by one or two characters ie search by S or Sm and it will pick up all names beginning with Sm. I know we can do this with combo box but in this instance I would like a list box. Any help appreciated

chestera
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can use the change event of the textbox

private sub txtSearch_change()

dim str as string

str=str & me.txtsearch.text

me.listbox.rowsource="select id, fullname from tablex where fullname like '" & str & "*'"

end sub
Avatar of chestera
chestera

ASKER

IrogSinta

That was a bad example I used that particular code for numerical searches. Thank you for that information

Alan
capricorn1

Many thanks

Alan