How do I keep a running count of characters in a text box? Help,please!

  • Thread starter Thread starter teddysnips
  • Start date Start date
T

teddysnips

I have an unbound text box called txtArea and I want to have a visual
clue on my form of how many characters are in the text box as I type
or delete them. I have put a label on the form called lblNumChar and
I've tried adding this

Me.lblNumChar.Caption = Len(Me.txtArea)

to various events but it doesn't seem to refresh in real time - i.e.
as I type.

The events I've tried adding it to are:

Form_Current
txtArea_AfterUpdate
txtArea_BeforeUpdate
txtArea_OnChange
txtArea_KeyPress
txtArea_KeyUp

Anyone any ideas of how to achieve this?

Thanks

Edward
 
The correct event to use here is on-change
(after update is good when a control is changed, BUT ONLY after the user is
done. I mean, while editing a text box, normally you don't want events
firing during that editing process, as you NEVER know when the user is
finished.

The event you need to track changes WHILE editing is called on-change

when you use on-change, the me.MyContorl.Value has NOT yet be committed, so
you have to use the .text property of the control (this property is ONLY
valid WHILE the control has focus).

So, in the on-change event go:

me.lblNumChar.Caption = len(me.txtArea.Text)
 
The correct event to use here is on-change
(after update is good when a control is changed, BUT ONLY after the user is
done. I mean, while editing a text box, normally you don't want events
firing during that editing process, as you NEVER know when the user is
finished.

The event you need to track changes WHILE editing is called on-change

when you use on-change, the me.MyContorl.Value has NOT yet be committed, so
you have to use the .text property of the control (this property is ONLY
valid WHILE the control has focus).

So, in the on-change event go:

me.lblNumChar.Caption = len(me.txtArea.Text)

That's it! Many thanks

Edward
 
Back
Top