Character counter

  • Thread starter Thread starter Wayne
  • Start date Start date
W

Wayne

Hello,

I have created a User form to allow users to enter data
onto a report. To ensure that data entered does not
exceed the space available I have limited the number of
characters that can be entered, I want to put a box on
the form that will show the user how many characters that
they have available and I would like it to update as they
type so they know how much space they have available.

eg. 100 characters available to start, as they type this
would decrease accordingly, so if they typed "Hello" the
box would show 95 available.

How can I do this?

Thanks in advance
 
One way:

Private Sub TextBox1_Change()
Const NUMCHARS As Integer = 100
Static noEvents As Boolean

If noEvents Then Exit Sub
noEvents = True
With TextBox1
.Text = Left(.Text, NUMCHARS)
TextBox2.Value = NUMCHARS - Len(.Text)
End With
noEvents = False
End Sub
 
Back
Top