title: How to limit number of characters of form field
body: <p>I have a form with an unbound comment field that we want to limit the number of characters in it. To make things as clean as possible, and to confirm it wasn't something else, I created a new form with two unbound text boxes. "Text0" is where you enter the data and "Text1" is the counter.</p>
  
  <pre><code>Private Sub Text0_Change()
      If Not IsNull(Me.Text0.Text) Then
          If Len(Me.Text0.Text) &gt; 20 Then
              Dim resp As Integer
              resp = MsgBox("Exceeded the number of characters allowed.", vbOKOnly, "Too long")
              Me.Text0 = Left(Me.Text0, 20)
          End If
          Me.Text1 = Len(Me.Text0.Text) &amp; _
          " /20 characters used."
      Else
          Me.Text1 = "0 /20 characters used."
      End If
  
  End Sub
  </code></pre>
  
  <p>To the issue. If you start entering data all is fine, it counts the length. However, when it hits the limit the box comes up but as soon as you click OK it blanks the field.</p>
  
  <p>I also tried to put in a validation rule but it doesn't fire until after loss of focus.</p>
  
  <p>How do you prevent it from killing the data already entered? The actual field limit is much longer and re-typing the comments won't fly.</p>