473,788 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UnBound Combo Box Behaviour

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 input mask the combo box behaves normally. However I
need the input mask to limit the max number of characters input to 40.
Also, the combo box "limit to list" property is set to false so the
user can select an existing value from the combo box + add/delete/
modify the combo box contents.

Can anyone please help.

Thx & Best Rgds,
Prakash.
Mar 5 '08 #1
9 2920
Obviously, the interaction with the Input Mask is the cause of your problem.

There are other ways to limit the number of characters... you can put a test
for length in the BeforeUpdate event and cancel the update if it is too
long. Some of the other ways you could use can be confusing, at best, and
irritating at worst, with a Combo, so I don't suggest those -- but if
catching the over-lengthy entry after it is too long is not to your liking,
you could search the newsgroup archives on KeyPress for a different
approach.

There are other, more complex approaches that one might use to try to tailor
the user experience, but they will lose the built-in "AutoExpand " capability
that lets you search the list so easily.

Larry Linson
Microsoft Office Access MVP
<pr************ *@gmail.comwrot e in message
news:22******** *************** ***********@s12 g2000prg.google groups.com...
>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 input mask the combo box behaves normally. However I
need the input mask to limit the max number of characters input to 40.
Also, the combo box "limit to list" property is set to false so the
user can select an existing value from the combo box + add/delete/
modify the combo box contents.

Can anyone please help.

Thx & Best Rgds,
Prakash.

Mar 5 '08 #2
On Mar 5, 11:02*am, "Larry Linson" <boun...@localh ost.notwrote:
Obviously, the interaction with the Input Mask is the cause of your problem.

There are other ways to limit the number of characters... you can put a test
for length in the BeforeUpdate event and cancel the update if it is too
long. Some of the other ways you could use can be confusing, at best, and
irritating at worst, with a Combo, so I don't suggest those -- but if
catching the over-lengthy entry after it is too long is not to your liking,
you could search the newsgroup archives on KeyPress for a different
approach.

There are other, more complex approaches that one might use to try to tailor
the user experience, but they will lose the built-in "AutoExpand " capability
that lets you search the list so easily.

*Larry Linson
*Microsoft Office Access MVP
Larry,

I agree that using a method other than the Input Mask for limiting the
length of the text in the combobox is good advice. Perhaps you missed
the word "unbound" or use bound forms exclusively. The BeforeUpdate/
Cancel is, if I remember correctly, a common way to validate bound
forms. Typically, validation for unbound forms is done in the
AfterUpdate event. However, the method I use for that purpose
validates in neither event.

Here's what I use to limit the length of entries in comboboxes:

'code behind form
Private Sub cbxComboName_Ke yPress(KeyAscii As Integer)
KeyAscii = LimitCombo(KeyA scii, cbxComboName, 50)
End Sub

'module code
Public Function LimitCombo(KeyA scii As Integer, cbxCombo As ComboBox,
intMax As Integer) As Integer
'If the field has reached its maximum then return 0
LimitCombo = KeyAscii
cbxCombo.SetFoc us
If Len(cbxCombo.Te xt) = intMax Then
If KeyAscii <8 Then LimitCombo = 0
End If
End Function

That will limit the contents of the combobox to 50 characters. If the
50 character limit is reached, the combobox ignores any more text.
Letting KeyAscii = 8 through allows the user to delete the last
character if they reach the limit and made a mistake on the final
character. This method should work on bound forms also and preserve
AutoExpand, but check to be sure.

James A. Fortune
CD********@Fort uneJames.com
Mar 5 '08 #3
On Mar 5, 2:08*pm, CDMAPos...@fort unejames.com wrote:
However, the method I use for that purpose validates in neither event.
I just tried pasting in text that was longer than the limit, so
perhaps use the method in combination with your normal validation
(i.e., check the length there also) or preclude ways to get around the
method's limitations.

James A. Fortune
CD********@Fort uneJames.com
Mar 5 '08 #4
On Mar 5, 11:20 pm, CDMAPos...@fort unejames.com wrote:
On Mar 5, 2:08 pm, CDMAPos...@fort unejames.com wrote:
However, the method I use for that purpose validates in neither event.

I just tried pasting in text that was longer than the limit, so
perhaps use the method in combination with your normal validation
(i.e., check the length there also) or preclude ways to get around the
method's limitations.

James A. Fortune
CDMAPos...@Fort uneJames.com

I'm sorry James, but please excuse my lack of Access knowledge. I sort
of understood the code of your previous post, but how do I check the
length when the user has pasted code into the combo box ? In which
event would I test and how ?

Thx for the help,
Prakash.
Mar 6 '08 #5

<pr************ *@gmail.comwrot e in message
news:ee******** *************** ***********@m34 g2000hsc.google groups.com...
On Mar 5, 11:20 pm, CDMAPos...@fort unejames.com wrote:
>On Mar 5, 2:08 pm, CDMAPos...@fort unejames.com wrote:
However, the method I use for that purpose validates in neither event.

I just tried pasting in text that was longer than the limit, so
perhaps use the method in combination with your normal validation
(i.e., check the length there also) or preclude ways to get around the
method's limitations.

James A. Fortune
CDMAPos...@For tuneJames.com


I'm sorry James, but please excuse my lack of Access knowledge. I sort
of understood the code of your previous post, but how do I check the
length when the user has pasted code into the combo box ? In which
event would I test and how ?
Jim's correct -- the AfterUpdate event is the proper place for the code. The
following code works for me, to replace however many characters are typed or
pasted into the Combo Box with just the first five. (My clients do not
expect their applications to "coddle" their users by being overly
solicitous -- if there's a limit, it does not have to be detected at the
first keystroke beyond that limit. They figure, I am sure, that typing
several extra characters and having them disappear is an incentive for the
user to learn and abide by the limit if they want to avoid the extra
typing.)

The AfterUpdate event does not fire until you press enter, or tab, or click
out of the Combo Box.

Private Sub cboName_AfterUp date()
If Len(cboName.Tex t) 5 Then
Me.cboName = Left(Me.cboName .Text, 5)
End If
End Sub

Larry Linson
Microsoft Office Access MVP
Mar 6 '08 #6
On Mar 5, 10:13*pm, prakashwadhw... @gmail.com wrote:
I'm sorry James, but please excuse my lack of Access knowledge. I sort
of understood the code of your previous post, but how do I check the
length when the user has pasted code into the combo box ? *In which
event would I test and how ?

Thx for the help,
Prakash.
Larry is correct about the event and the viability of his psychology.
The way the code I posted works is that when the limit is reached, the
user hits a metaphorical wall. A KeyAscii value of zero gets ignored
and all the other KeyAscii values get through. Thus, when the limit
is reached, all further keystrokes get ignored except for the
backspace character, whose ASCII value is 8. This prevents the user
from typing more characters than the field allows, but does not
prevent entering too many characters via other means. The editing
doesn't fire the AfterUpdate event until the editing is complete. If
someone gets around the system by pasting in more characters than the
limit, the AfterUpdate event can catch it then. Catching the length
at the keystroke level is a little awkward until users get used to
it. Using Larry's idea of simply using the AfterUpdate event isn't
perfect either. Maybe the KeyPress event could be used to pop up a
warning when the limit is reached that specifies the number of
characters allowed in the field instead of erecting a wall. The
AfterUpdate code can stay in case they flaunt the warning or try to
get around the system. It is also possible to code yet more events in
attempt to close all the loopholes, but usually a workable arrangement
can be found before that point is reached.

James A. Fortune
CD********@Fort uneJames.com
Mar 6 '08 #7
On Mar 7, 12:38 am, CDMAPos...@fort unejames.com wrote:
On Mar 5, 10:13 pm, prakashwadhw... @gmail.com wrote:
I'm sorry James, but please excuse my lack of Access knowledge. I sort
of understood the code of your previous post, but how do I check the
length when the user has pasted code into the combo box ? In which
event would I test and how ?
Thx for the help,
Prakash.

Larry is correct about the event and the viability of his psychology.
The way the code I posted works is that when the limit is reached, the
user hits a metaphorical wall. A KeyAscii value of zero gets ignored
and all the other KeyAscii values get through. Thus, when the limit
is reached, all further keystrokes get ignored except for the
backspace character, whose ASCII value is 8. This prevents the user
from typing more characters than the field allows, but does not
prevent entering too many characters via other means. The editing
doesn't fire the AfterUpdate event until the editing is complete. If
someone gets around the system by pasting in more characters than the
limit, the AfterUpdate event can catch it then. Catching the length
at the keystroke level is a little awkward until users get used to
it. Using Larry's idea of simply using the AfterUpdate event isn't
perfect either. Maybe the KeyPress event could be used to pop up a
warning when the limit is reached that specifies the number of
characters allowed in the field instead of erecting a wall. The
AfterUpdate code can stay in case they flaunt the warning or try to
get around the system. It is also possible to code yet more events in
attempt to close all the loopholes, but usually a workable arrangement
can be found before that point is reached.

James A. Fortune
CDMAPos...@Fort uneJames.com


Larry & James ... thank you very much for your replies. Sorry, I was
posted in the interior during the past week & could not reply.

If the user has exceeded an input length of 40 characters, I'd like to
flash a message via a msgbox & set focus back to that combo box.
However, much as I try, the focus moves back to the next control. Is
there anything I'm doing wrong here ?

Here's my code:

Private Sub txt_RcdFm_PdTo_ AfterUpdate()
If Len(txt_RcdFm_P dTo.Text) 40 Then
MsgBox "Length of 'PAID TO' cannot exceed 40 characters"
Me.txt_RcdFm_Pd To = Left(Me.txt_Rcd Fm_PdTo.Text, 40) '
SELECT characters exceeding 40 here
Me.txt_RcdFm_Pd To.SetFocus
End If
End Sub
What I'd like now is the cursor should go back to txt_RcdFm_PdTo and
the number of characters exceeding 40 should be SELECTED. i.e. if the
user has entered 55 characters, the last 15 characters should be
highlighted.

I think I might just have to use the beforeupdate event here.

Thx for all help.

Rgds,
Prakash.
Mar 11 '08 #8
On Mar 11, 11:43*am, prakashwadhw... @gmail.com wrote:
Larry & James ... thank you very much for your replies. Sorry, I was
posted in the interior during the past week & could not reply.

If the user has exceeded an input length of 40 characters, I'd like to
flash a message via a msgbox & set focus back to that combo box.
However, much as I try, the focus moves back to the next control. Is
there anything I'm doing wrong here ?

Here's my code:

Private Sub txt_RcdFm_PdTo_ AfterUpdate()
* * *If Len(txt_RcdFm_P dTo.Text) 40 Then
* * * * MsgBox "Length of *'PAID TO' *cannot exceed 40 characters"
* * * * Me.txt_RcdFm_Pd To = Left(Me.txt_Rcd Fm_PdTo.Text, 40) *'
SELECT characters exceeding 40 here
* * * * Me.txt_RcdFm_Pd To.SetFocus
* * *End If
End Sub

What I'd like now is the cursor should go back to *txt_RcdFm_PdTo *and
the number of characters exceeding 40 should be SELECTED. i.e. if the
user has entered 55 characters, the last 15 characters should be
highlighted.

I think I might just have to use the beforeupdate event here.

Thx for all help.

Rgds,
Prakash.
Use the SelStart and SelLength properties of the textbox after using
SetFocus, to highlight the text you want.

Something like (i.e., air code):

Private Sub txt_RcdFm_PdTo_ AfterUpdate()
Const PdMAX = 40
If Len(Nz(Me!txt_R cdFm_PdTo.Value , "")) PdMAX Then
'omit Me.txt_RcdFm_Pd To = Left( ... so you have something to select
With Me!txtRcdFm_PdT o
.SetFocus
.SelStart = PdMAX + 1
.SelLength = Len(.Value) - PdMAX
End With
End If
End Sub

James A. Fortune
CD********@Fort uneJames.com
Mar 11 '08 #9
On Mar 11, 9:40 pm, CDMAPos...@fort unejames.com wrote:
On Mar 11, 11:43 am, prakashwadhw... @gmail.com wrote:
Larry & James ... thank you very much for your replies. Sorry, I was
posted in the interior during the past week & could not reply.
If the user has exceeded an input length of 40 characters, I'd like to
flash a message via a msgbox & set focus back to that combo box.
However, much as I try, the focus moves back to the next control. Is
there anything I'm doing wrong here ?
Here's my code:
Private Sub txt_RcdFm_PdTo_ AfterUpdate()
If Len(txt_RcdFm_P dTo.Text) 40 Then
MsgBox "Length of 'PAID TO' cannot exceed 40 characters"
Me.txt_RcdFm_Pd To = Left(Me.txt_Rcd Fm_PdTo.Text, 40) '
SELECT characters exceeding 40 here
Me.txt_RcdFm_Pd To.SetFocus
End If
End Sub
What I'd like now is the cursor should go back to txt_RcdFm_PdTo and
the number of characters exceeding 40 should be SELECTED. i.e. if the
user has entered 55 characters, the last 15 characters should be
highlighted.
I think I might just have to use the beforeupdate event here.
Thx for all help.
Rgds,
Prakash.

Use theSelStartand SelLength properties of the textbox after using
SetFocus, to highlight the text you want.

Something like (i.e., air code):

Private Sub txt_RcdFm_PdTo_ AfterUpdate()
Const PdMAX = 40
If Len(Nz(Me!txt_R cdFm_PdTo.Value , "")) PdMAX Then
'omit Me.txt_RcdFm_Pd To = Left( ... so you have something to select
With Me!txtRcdFm_PdT o
.SetFocus
.SelStart= PdMAX + 1
.SelLength = Len(.Value) - PdMAX
End With
End If
End Sub

James A. Fortune
CDMAPos...@Fort uneJames.com

Thx James for the invaluable advice & code. Somehow though after
fiddling around, I opted to go with Allen Browne's code from his site:
http://allenbrowne.com/ser-34.html

I think it makes the Access unbound Text Box behave almost like a
bound text box.

What still beats me is why don't the MS developers make a small
property for an unbound textbox which would enable the user to specify
the maximum length of a string. eg: txt_MyTextbox.M axLength=40

Am I wrong in thinking along these lines ?

Thanks though to all who have helped.

Best Rgds,
Prakash.
Mar 19 '08 #10

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

Similar topics

6
2776
by: Megan | last post by:
I'm using an unbound combo box on a form as a record selector. I'm using the combo box to choose certain types of music, i.e. Alternative, Pop, Rock, etc…and then run a report based on the selection. My combo box, cboMuisicType, has a simple query, qryGetType, as a row source. This query retrieves data from my table, tblMusicTypes. This table has 2 fields: MusicID and MusicDesc. MusicID is the primary key and an autonumber. MusicDesc is...
2
6164
by: Todd | last post by:
Hello, I'm curious if anyone knows of a way (if one exists) to tell a form (in Access 2002 VBA) to sort on an unbound column of a combo box on the form. Here's what I want to do: A combo box on my form contains a category ID (bound column, not visible, long integer) for the items listed on the form and a description (unbound column, visible, string.) I can "Sort Ascending" and "Sort Descending" on the visible description in the...
2
3870
by: Todd | last post by:
Hi. I want to sort the records on my form (using either a continuous form or a datasheet) by the unbound "description" column in a combo box on the form (or in the datasheet.) Here's a rough text representation of what I'm talking about FORM Item Number Description Category (text box) (text box) (combo box - 2 columns)
2
3090
by: Wolfgang Kreuzer | last post by:
Hello all, I am converting an Axs 2.0 application to a2k (I know A2K is not the most current version but Axs 2.0 support ended and A2K is supported in our company amd on every PC). The form is part of an access projcet (ADP) and runs against SQL Server 2000. I have an bound form in endless view which contains a header with a combobox. This combobox is bound to an access query and shall allow to
0
1385
by: Wolfgang Kreuzer | last post by:
Hi, I am starting to migrate an Access 2.0 application to Access 2000 (I know it's not the latest version, but ist supported in our company). I found some funny behaviours where I could not find a solution in google groups. I retrieve data from sql server (2000) and created an access project. Form is bound to a view, in the form header there are two filter
3
2273
by: Stig | last post by:
Hi, Any help on this one will be greatly appreciated as I have spent too long banging my head against the screen trying to get it sorted. Basically I would like to have a select all records option in a combo box that is used in an unbound form for my report parameter. I have tried to explain it in further detail below: - In my DB I have numerous forms are used to input details into a table (TblMasterTable).
20
10828
by: Robert | last post by:
Need some help to stop me going around in circles on this one.... Have a nested subform (subform2) which simulates a continuous form for the record on the parent subform. Subform2 has rows of either an option button plus two text fields or a checkbox plus two text fields Am wanting to save the user entries into an underlying table. Tag property for each option button, check box or text field has the value of the key
8
8327
by: Robert | last post by:
I have a form (Worksheet) that works fine by itself. I have now created a seperate form (MainForm) that has a command button in the header and an unbound subform (FormFrame) in the Detail section. when the user clicks the command button, Worksheet is loaded into the subform control. At this point, some of the functions do not work. The user is prompted to enter a Parameter Value. Why wouldn't that form (Worksheet) work the same as a sub...
10
3506
by: themightypea | last post by:
Hi, I'm attempting to create a continuos form which allow the user to edit various fields for each item. Unfortunately, the data I need is spread over multiple tables so binding the control to the item in the underlying query prevents me from editing it. To get round this I've bound the controls to functions returning the data from an array, similar to the method described in http://www.thescripts.com/forum/thread193301.html. When the user...
0
9655
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
9498
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,...
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.