Count keystrokes

  • Thread starter Thread starter PennStan
  • Start date Start date
P

PennStan

I have a simple data entry form where users are requested to type in a
description of work performed. I want to limit the amount of text they can
enter and would like to display a "live" counter that tells them how many
characters they can enter. This counter would decrease as they made each
keystroke and stop at zero. Appreciate any suggestions or alternatives to
the counter.
 
Here's an example: http://cjoint.com/?fCrDQAoHPX

Userform's code is as follows.

Cheers,
--
AP

'---------------------------------------------------------------
Public bCancel As Boolean

Private Sub UserForm_Activate()
tbWorkDescription.Value = ActiveCell.Value
tbWorkDescription_Change
End Sub

Private Sub tbWorkDescription_Change()
Dim iCurrLen As Integer
iCurrLen = Len(tbWorkDescription.Text)
If iCurrLen >= iMaxChar Then
Beep
tbWorkDescription.Value = Left(tbWorkDescription.Value, iMaxChar)
iCurrLen = iMaxChar
End If
Me.lblCharLeft = iMaxChar - iCurrLen
End Sub

Private Sub cbOK_Click()
bCancel = False
Me.Hide
End Sub

Private Sub cbCancel_Click()
bCancel = True
Me.Hide
End Sub


Private Sub UserForm_Terminate()
cbCancel_Click
End Sub
'---------------------------------------------------------------------------
 
Try "Validation" in the Data menu. You can limit the number of text
characters people enter. Don't forget to leave a floating text box or
comment to explain your restrictions to the user.
HTH

Gilles
 

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