468,533 Members | 1,892 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,533 developers. It's quick & easy.

Counting characters entered in a text box and ...

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
Nov 13 '05 #1
4 30410
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:m4********************************@4ax.com...
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

Nov 13 '05 #2

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"
<Al*********@SeeSig.Invalid> wrote:
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

Nov 13 '05 #3
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:vn********************************@4ax.com...

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"
<Al*********@SeeSig.Invalid> wrote:
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

Nov 13 '05 #4
On Sun, 19 Sep 2004 16:13:09 +0800, "Allen Browne"
<Al*********@SeeSig.Invalid> wrote:
Did you actually test the TEXT property of the control,i.e.:
Len(Me.txtObjectName.Text)


OOPS! No I did not. Geesh! I'm such a doofus sometimes.
Thanks for your patience.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Smith | last post: by
3 posts views Thread by Brent | last post: by
5 posts views Thread by andy.lee23 | last post: by
5 posts views Thread by faizankhan666 | last post: by
reply views Thread by =?Utf-8?B?U3BlZWR5?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.