By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 1,783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

Counting characters entered in a text box and ...

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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.