dbTalk Databases Forums  

Limiting a Text Field's Input Size !

comp.databases.ms-access comp.databases.ms-access


Discuss Limiting a Text Field's Input Size ! in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
prakashwadhwani@gmail.com
 
Posts: n/a

Default Limiting a Text Field's Input Size ! - 02-25-2008 , 10:45 AM






I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?


Thx & Best Rgds,
Prakash.



Reply With Quote
  #2  
Old   
Larry Linson
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 12:17 PM






Is there some reason why you do not define the Field in the Table with the
maximum length you desire? If you do, and use that Field as the Control
Source of a TextBox on a Form, you will only be able to enter as many
characters as are defined.

Also, it sounds as if you are using an Input Mask. Most of us use Input
Masks rarely, if ever, because, except when input is being keyed and the
user tabs from one Text Box to another, they can seem "quirky" as you
describe.

Is it possible that you want Access TO BE DBase/Clipper to the extent that
you haven't expended the time and effort to learn "The Access Way"?
Expecting one software package to act/respond exactly or very similarly to
another is just inviting frustration.

Larry Linson
Microsoft Office Access MVP


<prakashwadhwani (AT) gmail (DOT) com> wrote

Quote:
I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?


Thx & Best Rgds,
Prakash.





Reply With Quote
  #3  
Old   
Salad
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 12:42 PM



prakashwadhwani (AT) gmail (DOT) com wrote:

Quote:
I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !
Not sure why you are using Format. If you click under the data tab you
can use an InputMask. Here's an example of limiting to 5 characters
with no guide.
CCCCC;;" "

Quote:
Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?
I'm not aware of a solution. That doesn't mean there isn't one. If I
entered in the GotFocus events
If len(Me.TextFieldName) > 5 then
Me.TextFieldName.SelStart = 5
Me.TextFieldName.SelLength = 2
Endif
and I tabbed to the field then the insertion point would be at the fifth
character and the 5th/6th chars would be selected.

ICGirls
http://www.youtube.com/watch?v=HJ0pABDh_gw

Quote:

Thx & Best Rgds,
Prakash.



Reply With Quote
  #4  
Old   
Albert D. Kallal
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 01:10 PM



You could try:

#1 - The number of characters you type into a text box will be limited by
the size of the text field in the table.

If you only want 15 chars, then you define the table field as 15 characters.


#2 - There is a input mask. (you mention that you might be using the
"format" of the text box...try using the input mask...you might find it
better).

If you have a unbound text box, or for the simple reason you want restrict
the number of characters into a text box, simply use a input mask. Bring up
the form in design mode, highlight the text box, display the properties
sheet, and then go to the data tab, you see a property called input mask.

put your cursor into that property, and hit f1 for help.

A few simply examples:

AAAAAAAAAAAA (allow any 12 characters, including space)

999999999999 (allow only numbers, including spaces)

???????????? (allow only letters, no numbers).

Quote:
Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?
There are workarounds, but keep in mind that word, Excel, and even web based
forms have this problem. This is really much the issue of using standard
windows interface as anything else. You can write code to try and change
this behavior, but in a sense you breaking just about how every windows
program functions.

I usually just click on the field BEFORE the one I want, and then hit tab
key. You could likely put some code on the fields "got focus" event, but
then your applications will enslave you to have to do this coding for every
field (users will expect that behavour -- this is a lot of work).

Note that you *can* change the behavior of what happens when you tab into a
field (select all of field, go to start of field, or go to end of field --
you find this global option in tools->options->keyboard tab).

It is not ideal that when you click on a text box, your cursor is not put to
the start, or end..but that just the way all text boxes on windows has
worked since windows 3.1 in 1991 came out. You can always double click on
the actual text to select the whole field. Another common key (standard to
windows) is to hit f2 to select, and then f2 again to jump to the start of
the field..

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal (AT) msn (DOT) com




Reply With Quote
  #5  
Old   
prakashwadhwani@gmail.com
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 01:49 PM



On Feb 25, 10:17 pm, "Larry Linson" <boun... (AT) localhost (DOT) not> wrote:
Quote:
Is there some reason why you do not define the Field in the Table with the
maximum length you desire? If you do, and use that Field as the Control
Source of a TextBox on a Form, you will only be able to enter as many
characters as are defined.

Also, it sounds as if you are using an Input Mask. Most of us use Input
Masks rarely, if ever, because, except when input is being keyed and the
user tabs from one Text Box to another, they can seem "quirky" as you
describe.

Is it possible that you want Access TO BE DBase/Clipper to the extent that
you haven't expended the time and effort to learn "The Access Way"?
Expecting one software package to act/respond exactly or very similarly to
another is just inviting frustration.

Larry Linson
Microsoft Office Access MVP

prakashwadhw... (AT) gmail (DOT) com> wrote in message

news:cd6b9ec2-a73c-4ac5-94dc-f49459f9e39a (AT) s8g2000prg (DOT) googlegroups.com...

I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?

Thx & Best Rgds,
Prakash.


Larry, First of all ... I owe you & all others a BIG apology. The test
box is "unbound". I need it that way for a particular reason. Yes, for
bound textboxes, I love the way they operate ... they simply pick up
the length from the table design & restrict it to that. Works
beautifully I must say.

Once again you are right ... I'm not using "Format" ... I'm using an
input mask (sorry again ... really). Now when I click in the box, the
cursor flashes somewhere in the middle, never at the beginning + the
input mask provides that ghastly underline to type on.

No ... I'm not looking for Access to behave like Dbase/Clipper ...
it's a far superior beast & I don't think I could go back to manually
designing forms. I just felt that the designers could have very easily
included a property for a text box wherein it's size could be limited.
Perhaps you & some other MVP's could forward such a suggestion to them
(if it seems reasonable). I think this is a simple feature & almost
everyone would require & benefit from it.

Thx for taking the trouble to answer.

Best Rgds,
Prakash.




Reply With Quote
  #6  
Old   
prakashwadhwani@gmail.com
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 01:53 PM



On Feb 25, 10:42 pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
prakashwadhw... (AT) gmail (DOT) com wrote:
I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !

Not sure why you are using Format. If you click under the data tab you
can use an InputMask. Here's an example of limiting to 5 characters
with no guide.
CCCCC;;" "

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?

I'm not aware of a solution. That doesn't mean there isn't one. If I
entered in the GotFocus events
If len(Me.TextFieldName) > 5 then
Me.TextFieldName.SelStart = 5
Me.TextFieldName.SelLength = 2
Endif
and I tabbed to the field then the insertion point would be at the fifth
character and the 5th/6th chars would be selected.

ICGirlshttp://www.youtube.com/watch?v=HJ0pABDh_gw



Thx & Best Rgds,
Prakash.

Hi Salad, pls read my reply to Larry ... my apologies ... i was using
input mask & not format.

Also, I am aware that using code as described by you, I can ensure I
end up at the 1st character .. it's just that it would require a lot
of coding for a lot of text boxes which doesn't seem necessary.

Thx again,
Prakash.


Reply With Quote
  #7  
Old   
prakashwadhwani@gmail.com
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 02:08 PM



On Feb 25, 11:10 pm, "Albert D. Kallal"
<PleaseNOOOsPAMmkal... (AT) msn (DOT) com> wrote:
Quote:
You could try:

#1 - The number of characters you type into a text box will be limited by
the size of the text field in the table.

If you only want 15 chars, then you define the table field as 15 characters.

#2 - There is a input mask. (you mention that you might be using the
"format" of the text box...try using the input mask...you might find it
better).

If you have a unbound text box, or for the simple reason you want restrict
the number of characters into a text box, simply use a input mask. Bring up
the form in design mode, highlight the text box, display the properties
sheet, and then go to the data tab, you see a property called input mask.

put your cursor into that property, and hit f1 for help.

A few simply examples:

AAAAAAAAAAAA (allow any 12 characters, including space)

999999999999 (allow only numbers, including spaces)

???????????? (allow only letters, no numbers).

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?

There are workarounds, but keep in mind that word, Excel, and even web based
forms have this problem. This is really much the issue of using standard
windows interface as anything else. You can write code to try and change
this behavior, but in a sense you breaking just about how every windows
program functions.

I usually just click on the field BEFORE the one I want, and then hit tab
key. You could likely put some code on the fields "got focus" event, but
then your applications will enslave you to have to do this coding for every
field (users will expect that behavour -- this is a lot of work).

Note that you *can* change the behavior of what happens when you tab into a
field (select all of field, go to start of field, or go to end of field --
you find this global option in tools->options->keyboard tab).

It is not ideal that when you click on a text box, your cursor is not put to
the start, or end..but that just the way all text boxes on windows has
worked since windows 3.1 in 1991 came out. You can always double click on
the actual text to select the whole field. Another common key (standard to
windows) is to hit f2 to select, and then f2 again to jump to the start of
the field..

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKal... (AT) msn (DOT) com

Albert, thank you for such a detailed & informative reply. My
apologies to you too ... I'm using an UNBOUND text box & an input mask
not the format like I'd mentioned. It's that underline/underscore when
I type in that bothers me while using an input mask.

There are 3 UNBOUND textboxes on this form for which I'd like the foll
behaviour:
if the text box is empty, then whenever the text box gets focus, the
cursor should go to the 1st character ... else it should follow the
default behaviour.

Would it be possible for either you or anyone else on this NG to
please post some sample code which would permit me to do this ?

In the meanwhile, I'll start fiddling with Salad's code, I think i
just may be able to modify it to my requirements.

Thx once again for the detailed answer.

Best Rgds,
Prakash.


Reply With Quote
  #8  
Old   
Arno R
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 02:17 PM




<prakashwadhwani (AT) gmail (DOT) com> schreef in bericht news:313ef1df-5017-46d9-89d3-49476a07643a (AT) e60g2000hsh (DOT) googlegroups.com...

Quote:
There are 3 UNBOUND textboxes on this form for which I'd like the foll
behaviour:
if the text box is empty, then whenever the text box gets focus, the
cursor should go to the 1st character ... else it should follow the
default behaviour.

Would it be possible for either you or anyone else on this NG to
please post some sample code which would permit me to do this ?

Well I don't use inputmasks that much (I hate them), but sometimes when I need them I write simple code like:

If IsNull(Me!FieldWithInputMask) then
Me!FieldWithInputmask.SelStart=0
Me!FieldWithInputmask.SelLength=0
End if

btw: I am using the click event (user clicks with mouse)

Arno R


Reply With Quote
  #9  
Old   
prakashwadhwani@gmail.com
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 02:31 PM



On Feb 25, 10:42 pm, Salad <o... (AT) vinegar (DOT) com> wrote:
Quote:
prakashwadhw... (AT) gmail (DOT) com wrote:
I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !

Not sure why you are using Format. If you click under the data tab you
can use an InputMask. Here's an example of limiting to 5 characters
with no guide.
CCCCC;;" "

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?

I'm not aware of a solution. That doesn't mean there isn't one. If I
entered in the GotFocus events
If len(Me.TextFieldName) > 5 then
Me.TextFieldName.SelStart = 5
Me.TextFieldName.SelLength = 2
Endif
and I tabbed to the field then the insertion point would be at the fifth
character and the 5th/6th chars would be selected.

ICGirlshttp://www.youtube.com/watch?v=HJ0pABDh_gw



Thx & Best Rgds,
Prakash.


I tried this, but the insertion point goes to the 1st character only
if I tab into the textbox ... not if i click in the textbox. Here's my
code ...

Private Sub txt_RcdFm_PdTo_GotFocus()
If Nz(Len(Me.txt_RcdFm_PdTo)) = 0 Then
MsgBox "Setting Cursor to 1st char"
Me.txt_RcdFm_PdTo.SelStart = 0
End If
End Sub

Will i have to put this same code in another event too ? Why doesn't
it work here ? The gotfocus event seems the most logical compared to
a MouseClick or MouseDown event, because in any case I'd have to even
check to see if the user has tabbed into the field. That means
checking in 2 events ?

Any ideas or workarounds please ?

Best Rgds,
Prakash.


Reply With Quote
  #10  
Old   
prakashwadhwani@gmail.com
 
Posts: n/a

Default Re: Limiting a Text Field's Input Size ! - 02-25-2008 , 02:57 PM



On Feb 26, 12:31 am, prakashwadhw... (AT) gmail (DOT) com wrote:
Quote:
On Feb 25, 10:42 pm, Salad <o... (AT) vinegar (DOT) com> wrote:







prakashwadhw... (AT) gmail (DOT) com wrote:
I've used Dbase/Clipper for years & Access for a little while now but
Access doesn't seem to have any elegant solution to limiting the size
of a text box ... i.e. the max number of characters that can be
entered into a text box.

In Dbase/Clipper eg. if memory serves me correctly, it's a 1-line
elegant solution ..
@ row, col get variable picture "@R50"

or ... I could say var1=space(50)

Now when I try to enter data into var1 it will allow a max of 50
characters.

Why don't the Access team make a small property specifying the max num
of characters enterable ?

I have seen Allen Browne's solution:
http://allenbrowne.com/ser-34.html

I was just wondering if there's anything better.

I tried using the format property with "C" repeated say 30 times ...
but when entering data into the box I now see an underline/underscore
over which I have to type ... looks ugly !

Not sure why you are using Format. If you click under the data tab you
can use an InputMask. Here's an example of limiting to 5 characters
with no guide.
CCCCC;;" "

Also ... when I click in the text box, the cursor goes somewhere in
the middle of the text box & I have to press the home key to go to the
beginning. Is there any workaround for this ?

I'm not aware of a solution. That doesn't mean there isn't one. If I
entered in the GotFocus events
If len(Me.TextFieldName) > 5 then
Me.TextFieldName.SelStart = 5
Me.TextFieldName.SelLength = 2
Endif
and I tabbed to the field then the insertion point would be at the fifth
character and the 5th/6th chars would be selected.

ICGirlshttp://www.youtube.com/watch?v=HJ0pABDh_gw

Thx & Best Rgds,
Prakash.

I tried this, but the insertion point goes to the 1st character only
if I tab into the textbox ... not if i click in the textbox. Here's my
code ...

Private Sub txt_RcdFm_PdTo_GotFocus()
If Nz(Len(Me.txt_RcdFm_PdTo)) = 0 Then
MsgBox "Setting Cursor to 1st char"
Me.txt_RcdFm_PdTo.SelStart = 0
End If
End Sub

Will i have to put this same code in another event too ? Why doesn't
it work here ? The gotfocus event seems the most logical compared to
a MouseClick or MouseDown event, because in any case I'd have to even
check to see if the user has tabbed into the field. That means
checking in 2 events ?

Any ideas or workarounds please ?

Best Rgds,
Prakash.


Ok ... I've got it to work by using the foll code:

Private Sub txt_RcdFm_PdTo_GotFocus()
If Nz(Len(Me.txt_RcdFm_PdTo)) = 0 Then 'if the textbox is
EMPTY
Me.txt_RcdFm_PdTo.SelStart = 0 'Position Cursor at
1st char
SendKeys "{HOME}"
Else 'if the textbox has
some data
Me.txt_RcdFm_PdTo.SelLength = 0
Me.txt_RcdFm_PdTo.SelStart = Len(Me.txt_RcdFm_PdTo)
'Position Cursor after LAST char
End If
End Sub

My problem is that if I tab into the textbox & it has data the cursor
is positioned correctly, but if I CLICK into the textbox having data,
the cursor flashes at the clicked position.

Is there another workaround like I've used Sendkeys above ? Sendkeys
seems to work perfectly for both - if I tab into & if i click into the
textbox.

Rgds,
Prakash.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.