Had the exact same problem. I was typing in a text box, and
having entries in a listbox select or deselect based on what
was typed. In my case, I was allowing multi-select, so you
may not have to do all this.
Private Sub txtSearchPhysicians_Change()
Dim sEntry As String
Dim sSearch As String
Dim inx As Integer
Dim bFound As Boolean
Dim iSelStart As Integer
Dim iSelLength As Integer
bFound = False
' Create sEntry and search for it
sEntry = UCase(txtSearchPhysicians.Text & "")
For inx = 0 To lstPhysicians.ListCount - 1
sSearch = Left(UCase(lstPhysicians.Column(2, inx)),
Len(sEntry))
' Embedded spaces are a problem
sSearch = Replace(sSearch, " ", "_")
If sEntry = sSearch And Len(sEntry) > 0 Then
lstPhysicians.Selected(inx) = True
If Not bFound Then
bFound = True
iSelStart = txtSearchPhysicians.SelStart
iSelLength = txtSearchPhysicians.SelLength
lstPhysicians.SetFocus
' This is the repositioning magic here. The First
..ListIndex call
' moves the listbox below the desired entry. This
is to show
' the entry in context.
lstPhysicians.ListIndex = Min(inx + 5,
lstPhysicians.ListIndex)
' This next one makes sure you see the entry.
lstPhysicians.ListIndex = inx
txtSearchPhysicians.SetFocus
txtSearchPhysicians.SelStart = iSelStart
txtSearchPhysicians.SelLength = iSelLength
End If
Else
lstPhysicians.Selected(inx) = False
End If
Next
End Sub
colleen<co**************@rl.gov> 4/27/2005 2:16:51 PM
I have a function that will search through a list box and
select a
variable. I can get the item in the list box to select,
butI cannot
get the list box to go to the selected item. So if the
useridentifies
a variable at the bottom of the list, the list box may not
show it.
Works in Access2000. THIS SEEMS LIKE THIS WOULD BE A
SIMPLE PROBLEM TO
FIX.