473,513 Members | 2,397 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 2910
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.comwrote in message
news:22**********************************@s12g2000 prg.googlegroups.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...@localhost.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_KeyPress(KeyAscii As Integer)
KeyAscii = LimitCombo(KeyAscii, cbxComboName, 50)
End Sub

'module code
Public Function LimitCombo(KeyAscii As Integer, cbxCombo As ComboBox,
intMax As Integer) As Integer
'If the field has reached its maximum then return 0
LimitCombo = KeyAscii
cbxCombo.SetFocus
If Len(cbxCombo.Text) = 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********@FortuneJames.com
Mar 5 '08 #3
On Mar 5, 2:08*pm, CDMAPos...@fortunejames.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********@FortuneJames.com
Mar 5 '08 #4
On Mar 5, 11:20 pm, CDMAPos...@fortunejames.com wrote:
On Mar 5, 2:08 pm, CDMAPos...@fortunejames.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...@FortuneJames.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.comwrote in message
news:ee**********************************@m34g2000 hsc.googlegroups.com...
On Mar 5, 11:20 pm, CDMAPos...@fortunejames.com wrote:
>On Mar 5, 2:08 pm, CDMAPos...@fortunejames.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...@FortuneJames.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_AfterUpdate()
If Len(cboName.Text) 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********@FortuneJames.com
Mar 6 '08 #7
On Mar 7, 12:38 am, CDMAPos...@fortunejames.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...@FortuneJames.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_PdTo.Text) 40 Then
MsgBox "Length of 'PAID TO' cannot exceed 40 characters"
Me.txt_RcdFm_PdTo = Left(Me.txt_RcdFm_PdTo.Text, 40) '
SELECT characters exceeding 40 here
Me.txt_RcdFm_PdTo.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_PdTo.Text) 40 Then
* * * * MsgBox "Length of *'PAID TO' *cannot exceed 40 characters"
* * * * Me.txt_RcdFm_PdTo = Left(Me.txt_RcdFm_PdTo.Text, 40) *'
SELECT characters exceeding 40 here
* * * * Me.txt_RcdFm_PdTo.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_RcdFm_PdTo.Value, "")) PdMAX Then
'omit Me.txt_RcdFm_PdTo = Left( ... so you have something to select
With Me!txtRcdFm_PdTo
.SetFocus
.SelStart = PdMAX + 1
.SelLength = Len(.Value) - PdMAX
End With
End If
End Sub

James A. Fortune
CD********@FortuneJames.com
Mar 11 '08 #9
On Mar 11, 9:40 pm, CDMAPos...@fortunejames.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_PdTo.Text) 40 Then
MsgBox "Length of 'PAID TO' cannot exceed 40 characters"
Me.txt_RcdFm_PdTo = Left(Me.txt_RcdFm_PdTo.Text, 40) '
SELECT characters exceeding 40 here
Me.txt_RcdFm_PdTo.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_RcdFm_PdTo.Value, "")) PdMAX Then
'omit Me.txt_RcdFm_PdTo = Left( ... so you have something to select
With Me!txtRcdFm_PdTo
.SetFocus
.SelStart= PdMAX + 1
.SelLength = Len(.Value) - PdMAX
End With
End If
End Sub

James A. Fortune
CDMAPos...@FortuneJames.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.MaxLength=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
2753
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...
2
6146
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,...
2
3832
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) ...
2
3047
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....
0
1379
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...
3
2255
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...
20
10781
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...
8
8307
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...
10
3474
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,...
0
7269
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...
0
7559
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...
1
7123
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...
0
7542
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...
0
5701
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...
1
5100
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...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
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...
0
1611
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

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.