By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,390 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

List Box Set Focus Problem in MS Access 2003

P: n/a
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, but I cannot
get the list box to go to the selected item. So if the user identifies
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.

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Nov 13 '05 #2

P: n/a
Thanks Kevin! It was actually this pesky line:

ctl.ListIndex = i

You have made my users very happy!

Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.