Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting number of charactors in a string while typing

Status
Not open for further replies.

leckie

Programmer
Apr 19, 2001
65
GB
Is their a way of counting the charactors in a text box as a user is typing and updating an unbound field as the user continues to type ? (not after updated)
any help much appreciated . .

regards Leckie
 
The KeyPress event procedure (of your TextBox field) is a good place to perform your duty.
If you want to avoid to take care of backspace, del ... use the Len function on each Event to get the actual number of displayable characters.
 
I've tried the key press event but to not avail . . have you a suggestion to the code I should use

I tried this:

Private Sub txtmessage_KeyPress(KeyAscii As Integer)
[chr] = Len([txtmessage])
End Sub
 
Hi,

The keypress event may cause some problems when you want to retrieve that data.
I would suggest that you use the change event off the textbox

Say you have a label "Label1" where you put the number off characters each time you type in something in your textbox
This would be the code

Private Sub Text1_Change()
Label1.Caption= Len(Text1)
End Sub

Hope this is what you're looking for
Good luck
 

Use the Text property of the text box to get the length of the typed text. Put this code in the key press or change event of txtMessage.

txtLength = Len(txtMessage.Text) Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top