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 txtSearchPhysic ians_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(txtSearch Physicians.Text & "")
For inx = 0 To lstPhysicians.L istCount - 1
sSearch = Left(UCase(lstP hysicians.Colum n(2, inx)),
Len(sEntry))
' Embedded spaces are a problem
sSearch = Replace(sSearch , " ", "_")
If sEntry = sSearch And Len(sEntry) > 0 Then
lstPhysicians.S elected(inx) = True
If Not bFound Then
bFound = True
iSelStart = txtSearchPhysic ians.SelStart
iSelLength = txtSearchPhysic ians.SelLength
lstPhysicians.S etFocus
' 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.L istIndex = Min(inx + 5,
lstPhysicians.L istIndex)
' This next one makes sure you see the entry.
lstPhysicians.L istIndex = inx
txtSearchPhysic ians.SetFocus
txtSearchPhysic ians.SelStart = iSelStart
txtSearchPhysic ians.SelLength = iSelLength
End If
Else
lstPhysicians.S elected(inx) = False
End If
Next
End Sub
colleen<co***** *********@rl.go v> 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.