the_Apple
asked on
listbox locating records
Hi All, I have a searchbox with comman button to search data in a listbox, the code below for the search and locating the records. The search works great but the record selected is usually not showing in the listbox. I always have to scroll one record down in the listbox.
I tried to change the height of the listbox but it is still not working. the search finds the right record but if the listbox showing 10 records, it is always the one above the first one from 1-10.
I am not sure if there is an easier or better way to do this.....
Dim strSearch As String
Dim RowIndex As Long
Dim numrows As Long
numrows = CInt((List96.Height) / 67)
strSearch = "*" & txtsearch.Value & "*"
With Me.List96
If .ListCount > 0 Then
For RowIndex = 0 To .ListCount - 1
If .Column(0, RowIndex) Like strSearch Or .Column(1, RowIndex) Like strSearch Or .Column(2, RowIndex) Like strSearch Then
.SetFocus '
If ((RowIndex + (numrows - 1)) <= List96.ListCount) Then
Me.List96.ListIndex = RowIndex + (numrows - 1)
Else
Me.List96.ListIndex = RowIndex
End If
Me.List96.ListIndex = RowIndex
If MsgBox("Do you want to continue searching?", vbQuestion + vbYesNo, "Searching...") = vbNo Then
Exit For
End If
End If
Next RowIndex
End If
End With
I tried to change the height of the listbox but it is still not working. the search finds the right record but if the listbox showing 10 records, it is always the one above the first one from 1-10.
I am not sure if there is an easier or better way to do this.....
Dim strSearch As String
Dim RowIndex As Long
Dim numrows As Long
numrows = CInt((List96.Height) / 67)
strSearch = "*" & txtsearch.Value & "*"
With Me.List96
If .ListCount > 0 Then
For RowIndex = 0 To .ListCount - 1
If .Column(0, RowIndex) Like strSearch Or .Column(1, RowIndex) Like strSearch Or .Column(2, RowIndex) Like strSearch Then
.SetFocus '
If ((RowIndex + (numrows - 1)) <= List96.ListCount) Then
Me.List96.ListIndex = RowIndex + (numrows - 1)
Else
Me.List96.ListIndex = RowIndex
End If
Me.List96.ListIndex = RowIndex
If MsgBox("Do you want to continue searching?", vbQuestion + vbYesNo, "Searching...") = vbNo Then
Exit For
End If
End If
Next RowIndex
End If
End With
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This would still allow you to do that... youd just need to enter new search criteria in the txtSearch box. If you clear the text box you will see all records again.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER