sir,
I have a problem that I have a list box ,in which i have the nemes e.g.ajay,abhay,abhinav,bani,coma,naveen etc. and have a text box for searching the name in the text box.When i press the a,it will show ajay,abhay and the abhinav.Which is good.when i add ab in text box,it will show abhay and abhinav,which is also right,but when I backspace the ab to a,then it will not show the names ajay,abhay and the abhinav,but it will show the abhay and the abhinav.Perhaps u understand my problem.My code is

Private Sub txtSearch1_Change()
    Dim intloopindex As Integer
    Dim charPos As Integer
    Dim intcount As Integer
    Dim strvariable() As String
    If Len(txtSearch1.Text) = 0 Then
        lstUserinfo.Clear
        Call Form_Load
        Exit Sub
    End If
    If lstUserinfo.ListCount > 0 Then
        ReDim strvariable(0)
        Dim i As Integer
        Dim j As Integer
        For i = lstUserinfo.ListCount - 1 To 0 Step -1
            If (InStr(1, lstUserinfo.List(i), txtSearch1.Text, vbTextCompare) = 1) Then
                strvariable(j) = lstUserinfo.List(i)
                j = j + 1
                ReDim Preserve strvariable(j)
            End If
        Next
        lstUserinfo.Clear
        For j = 0 To UBound(strvariable) - 1
            lstUserinfo.AddItem strvariable(j)
        Next
    End If

.
Please help me..............

Okay,... Just a couple of points here...

To begin with so you do not have to load, clear, and then reload you list box, I would suggest you add another listbox or some other control and load the information into it only one time. Then make that contol invisible (visable=false). See example...

Option Explicit

Private Sub Form_Load()
List1.Visible = False
List1.AddItem "abc"
List1.AddItem "aba"
List1.AddItem "aab"
List1.AddItem "abh"
List1.AddItem "bbj"
List1.AddItem "oft"
End Sub

Private Sub Text1_Change()
Dim MyArray() As String, ForLoopCounter As Integer
If Trim(Text1.Text) = "" Then
  List2.Clear
  Exit Sub
End If
List2.Clear
For ForLoopCounter = 0 To List1.ListCount - 1
  If Left(List1.List(ForLoopCounter), Len(Text1.Text)) = Text1.Text Then
    List2.AddItem List1.List(ForLoopCounter)
  End If
Next ForLoopCounter
End Sub

Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.