Connecting Tech Pros Worldwide Forums | Help | Site Map

Counting characters entered in a text box and ...

Lauren Wilson
Guest
 
Posts: n/a
#1: Nov 13 '05
Using VBA code on a form, does anyone know the most effective way to
count characters entered into a text box AS they are being entered and
displaying the number of characters remaining to the user?

Thanks

Allen Browne
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Counting characters entered in a text box and ...


Use the Change event of the text box to count the Len() of the Text
property, and assign the result to an unbound text box:

Private Sub Text1_Change()
Me.Text2 = 255 - Len(Me.Text1.Text)
End Sub

The example assumes there are 255 charaters available. If the control is
bound to a Text field, you could get the number of charaters from:
Me.RecordsetClone.Fields("MyField").Size

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Lauren Wilson" <???@???.???> wrote in message
news:m45ik055ukpvfntbd4iqdlgdai7dc8savn@4ax.com...[color=blue]
> Using VBA code on a form, does anyone know the most effective way to
> count characters entered into a text box AS they are being entered and
> displaying the number of characters remaining to the user?
>
> Thanks[/color]


Lauren Wilson
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Counting characters entered in a text box and ...



Well Allen, I tried this. The change event does seem to fire with
EACH keystroke inside the text box but the value it uses for the
calculation is always the old value (Me.txtObjectName).

What I need to do is decrement the character counter on EACH keystroke
and update the remaining character count even before the record is
saved. I've tried using the Keypress event but that has it's own set
of problems.

Is there a way to have a real-time display of the remaining characters
as the user types into the field but before they save the record?

Thanks again for all your great contributions to this group.


On Thu, 16 Sep 2004 12:55:37 +0800, "Allen Browne"
<AllenBrowne@SeeSig.Invalid> wrote:
[color=blue]
>Use the Change event of the text box to count the Len() of the Text
>property, and assign the result to an unbound text box:
>
>Private Sub Text1_Change()
> Me.Text2 = 255 - Len(Me.Text1.Text)
>End Sub
>
>The example assumes there are 255 charaters available. If the control is
>bound to a Text field, you could get the number of charaters from:
>Me.RecordsetClone.Fields("MyField").Size[/color]
Allen Browne
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Counting characters entered in a text box and ...


Did you actually test the TEXT property of the control,i.e.:
Len(Me.txtObjectName.Text)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Lauren Wilson" <???@???.???> wrote in message
news:vn9qk05ljkbfka3k9u9db5k26jvoobtpe5@4ax.com...[color=blue]
>
> Well Allen, I tried this. The change event does seem to fire with
> EACH keystroke inside the text box but the value it uses for the
> calculation is always the old value (Me.txtObjectName).
>
> What I need to do is decrement the character counter on EACH keystroke
> and update the remaining character count even before the record is
> saved. I've tried using the Keypress event but that has it's own set
> of problems.
>
> Is there a way to have a real-time display of the remaining characters
> as the user types into the field but before they save the record?
>
> Thanks again for all your great contributions to this group.
>
>
> On Thu, 16 Sep 2004 12:55:37 +0800, "Allen Browne"
> <AllenBrowne@SeeSig.Invalid> wrote:
>[color=green]
>>Use the Change event of the text box to count the Len() of the Text
>>property, and assign the result to an unbound text box:
>>
>>Private Sub Text1_Change()
>> Me.Text2 = 255 - Len(Me.Text1.Text)
>>End Sub
>>
>>The example assumes there are 255 charaters available. If the control is
>>bound to a Text field, you could get the number of charaters from:
>>Me.RecordsetClone.Fields("MyField").Size[/color][/color]


Lauren Wilson
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Counting characters entered in a text box and ...


On Sun, 19 Sep 2004 16:13:09 +0800, "Allen Browne"
<AllenBrowne@SeeSig.Invalid> wrote:
[color=blue]
>Did you actually test the TEXT property of the control,i.e.:
> Len(Me.txtObjectName.Text)[/color]

OOPS! No I did not. Geesh! I'm such a doofus sometimes.
Thanks for your patience.
Closed Thread