473,396 Members | 1,992 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,396 software developers and data experts.

Dynamic combo box - limit selection based on user entry

I am using a combo box to select the key to records and then go to the
selected record on my form. Works well. However, the list, which
contains people names, is rather long. What I would like to do is to
allow entry of one or more letters of the beginning of the last name,
like "j" for someone named Johnson (or Johnston) , where the list in the
combo box will only show names equivalent to a "like {j*}" clause.

So far it appears Access wants the combo box select statement to be
text, not using any field variable names.

Suggestions?
Bob Alston
Nov 13 '05 #1
3 8195
Bob Alston <Tu**********@cox.net> wrote:
I am using a combo box to select the key to records and then go to the
selected record on my form. Works well. However, the list, which
contains people names, is rather long. What I would like to do is to
allow entry of one or more letters of the beginning of the last name,
like "j" for someone named Johnson (or Johnston) , where the list in the
combo box will only show names equivalent to a "like {j*}" clause.

So far it appears Access wants the combo box select statement to be
text, not using any field variable names.

Suggestions?
Bob Alston


Well...here's some code
Private Sub Combo0_KeyDown(KeyCode As Integer, Shift As Integer)
MsgBox "keycode is " & KeyCode
End Sub

Here's some more code.
Private Sub Combo0_Change()
MsgBox "I changed " & Me.Combo0.SelStart
End Sub

The Change event works semi-OK. Let's say I have a customer called
JoeBlow Tires. As I type J, selstart is 1. When I enter o, selstart is
2. But there is a problem. Change does not recognize backspacing.
So..you may want KeyDown.

You'd set a global variable to "" when it gets focus. Then grab the
keys and store them to the global variable. Ex:
Option Compare Database
Option Explicit
Dim strGlobal As String

Private Sub Combo0_GotFocus()
strGlobal = ""
End Sub
Private Sub Combo0_KeyDown(KeyCode As Integer, Shift As Integer)
Dim strWhere as STring
If KeyCOde <> 37 then
strGlobal = strGlobal & keycode
else
If Len(strGlobal) > 1 then
strGlobal = Left(strGlobal,len(strGlobal)-1
else
strGlobal = ""
Endif
Endif
If strGlobal > ""
strWhere = " Where Left(CustomerName," & _
Len(strGlobal) & ") = '" strGlobal & "'"
Endif
Me.Combo0.RowSource = "Select CustomerID, CustomerName From
Customers " & strWhere & " Order By CustomerName
End Sub

Let's say strGlobal was 3 chars at this point. The where clause would
be "Where Left(CustomerName,3) = 'Joe'"

Changing the rowsource will pull only those records that meet your input
at that point. You may have to check for tab keys, enter keys,
etc...but you have the idea.
Nov 13 '05 #2
"Bob Alston <Tu**********@cox.net>" <Tu**********@cox.net> wrote in message news:<CdPkd.53364$_g6.34507@okepread03>...
I am using a combo box to select the key to records and then go to the
selected record on my form. Works well. However, the list, which
contains people names, is rather long. What I would like to do is to
allow entry of one or more letters of the beginning of the last name,
like "j" for someone named Johnson (or Johnston) , where the list in the
combo box will only show names equivalent to a "like {j*}" clause.

So far it appears Access wants the combo box select statement to be
text, not using any field variable names.

Suggestions?
Bob Alston


You can give a query as the source for the combo box

Sunil Korah
Nov 13 '05 #3
hb*****@indiatimes.com (Sunil Korah) wrote in message news:<72**************************@posting.google. com>...
"Bob Alston <Tu**********@cox.net>" <Tu**********@cox.net> wrote in message news:<CdPkd.53364$_g6.34507@okepread03>...
I am using a combo box to select the key to records and then go to the
selected record on my form. Works well. However, the list, which
contains people names, is rather long. What I would like to do is to
allow entry of one or more letters of the beginning of the last name,
like "j" for someone named Johnson (or Johnston) , where the list in the
combo box will only show names equivalent to a "like {j*}" clause.

So far it appears Access wants the combo box select statement to be
text, not using any field variable names.

Suggestions?
Bob Alston


You can give a query as the source for the combo box

Sunil Korah


OK. I tried your code two above. Fixed the couple of syntax errors.
When I enter a character it gets written to the field. If I click on
the "down arror" again, the code is applied and I get a query
restricted by the one character I have entered. If I do it again, it
is as if the process ends after 1 character and it gets stored in the
field.

Suggestions?

Bob Alston
Nov 13 '05 #4

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

Similar topics

13
by: mr_burns | last post by:
hi, is it possible to change the contents of a combo box when the contents of another are changed. for example, if i had a combo box called garments containing shirts, trousers and hats, when...
2
by: Danny | last post by:
I have a combo box look up and list items in a table, it is not bound. It works fine but how can I prevent the users from entering in there own data? i have an 'on change' event that when it...
3
by: mal | last post by:
Sorry for repost - system added to another subject for some reason Have tried numerous ideas from the group to solve this one. It is such a simple example that it should be straightforward ! I...
9
by: Bob Alston | last post by:
In 2002, "GrayJay" posted the following code: I did this in a jazz record catalogue to find composers - On a form "frmComposers" Create a text box - txtFindComposer, and add the following sub...
2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
2
by: Robert | last post by:
Am using a nested continuous bound subform to add multiple records to the underlying table. One of the fields is based on a limit to list combo box. Any suggestions on best way to progressively...
1
by: Richard | last post by:
Very typical normal data Table One ------ One.OneID (PK) One.Name One.Description One.TwoID (FK) One.ThreeID (FK) ....
9
by: prakashwadhwani | last post by:
I have an unbound combo box in the form header. I have used an input mask "CCCC" 40 times to limit the max number of characters to 40. When I tab into the combo box & press a character say "K"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.