473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

List Box Set Focus Problem in MS Access 2003

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
2 5658
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
Thanks Kevin! It was actually this pesky line:

ctl.ListIndex = i

You have made my users very happy!

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: William Case | last post by:
Hi folks, Screen.PreviousControl.SetFocus works fine to select the control that had focus prior to the one that NOW has focus. Unfortunately, I've not discovered a VBA code way to get the name...
1
by: Dec | last post by:
Ok to simplify things I'll just give an example. This is pretty much what I want to do (minus the postcode): http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF I have relatively little...
1
by: Jan Nordgreen | last post by:
I use Access 2003 and WinXP. When my form has Allowedits = false I can not choose a row in the list box that shows some of the fields in the form's record source table. Why not? What is the...
2
by: S P Arif Sahari Wibowo | last post by:
Hi! Do you know how to put a form's Access-Visual-Basic-code that will force the form to be inserted, while the user has not type anything in the form, without changing focus, selection, etc.? ...
1
by: Gil | last post by:
hello, im automating mappoint through access to get mileage between two address fields. when ever i call the function it makes mappoint the focus, and i have to reclick the access screen to regain...
3
by: rhobson2 | last post by:
Hello, I wrote a database applicaiton using Access XP (2002) and everything has been working good for the client until they purchased a couple of new computers with Access 2003. The meetings...
0
by: jvitti | last post by:
I recently upgraded from Access 2000 to Access 2007 and I am having trouble with moving the focus from 1 form to another. While doing data entry if a similar claim is found the claim view form...
16
by: google | last post by:
In a continuous form the following code is under a button in the form header. In Access 2003 and earlier, this goes to a new record, then adds relevant data to that new record. DoCmd.GoToRecord...
1
by: MerlinS | last post by:
Using Access 2003. I have a form and a subform. On the main form, one of the fields is a lost box, which lists line numbers ie 1, 2, 3 etc. Then the list box is clicked, the subform corresponding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.