473,796 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8211
Bob Alston <Tu**********@c ox.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.SelSt art
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(CustomerNa me," & _
Len(strGlobal) & ") = '" strGlobal & "'"
Endif
Me.Combo0.RowSo urce = "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(CustomerNa me,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**********@c ox.net>" <Tu**********@c ox.net> wrote in message news:<CdPkd.533 64$_g6.34507@ok epread03>...
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*****@indiati mes.com (Sunil Korah) wrote in message news:<72******* *************** ****@posting.go ogle.com>...
"Bob Alston <Tu**********@c ox.net>" <Tu**********@c ox.net> wrote in message news:<CdPkd.533 64$_g6.34507@ok epread03>...
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
2899
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 the user selects shirts another combo box called 'size' would contain sizes in relation to shirts (ie. chest/neck size). the same would occur for trousers and hats. when the user selects an option in the garment combo box, the options available...
2
3142
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 changes, it does something else to a field based on their selection. I also have the LimitTOList on, but when they click in there, they get an error first that says the 2110-focus cannot move the focus to this control. (I have the .setfocus
3
3211
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 just want to add a new item to a combo that has data from a file, by typing in the new value , adding to the file and the requerying to get the new valus in the list. i.e. a data entry and data display combo box. I select an item from cmb1 and...
9
3404
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 Private Sub txtFindComposer_Change() Requery Me!.SetFocus
2
2560
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 and are called like a static control. Here is the problem that I need to solve. The processing overhead that occurs to determine what dynamic controls need to be added involves business logic and a query or queries of data in a sql server...
2
2408
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 update the combo box query so that for each new record being entered the combo box list excludes items in the combo box list previously selected. Aim is to prevent user from selecting the same combo list item more than once if the user has already...
1
2765
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
2923
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" for example, the entire first match gets filled in the combo box and the cursor goes to the last character of the combo box. So I can't effectively search for a "KI" until I backspace the entire entry which has got filled in. Once i remove the...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10187
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.