Label showing number of chars left in a text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to make a label next to a text box count down the number of character
space left in the text box that updates real time. I'v made the code below
but I can't find a correct event to make it refresh with every keypress

Private Sub txtNotes_KeyUp(KeyCode As Integer, Shift As Integer)
Dim Length As String
Length = 255 - Len(txtNotes.Value)
lblLeftNotes.Caption = "(" & Length & ")"
End Sub
 
Adam said:
I want to make a label next to a text box count down the number of
character space left in the text box that updates real time. I'v made
the code below but I can't find a correct event to make it refresh
with every keypress

Private Sub txtNotes_KeyUp(KeyCode As Integer, Shift As Integer)
Dim Length As String
Length = 255 - Len(txtNotes.Value)
lblLeftNotes.Caption = "(" & Length & ")"
End Sub

txtNotes.Value is not updated until the control is actually updated. To see
changes while you are typing use txtNotes.Text.
 
Put it in the On Change event instead and change the code to this

Dim Length As Integer
Length = 255 - Len(txtNotes.Text)
lblLeftNotes.Caption = "(" & Length & ")"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top