Character Limits

  • Thread starter Thread starter Very Basic User
  • Start date Start date
V

Very Basic User

Hello,

I want to limit an entry to a certain number of characters. I know this is
easy in an original table, but I'm struggling because I did not limit in the
past and don't want to corrupt the existing data. Can I allow a table to
store any amout of characters, but limit the characters that a form will take
from this point forward?
 
Very Basic User said:
Hello,

I want to limit an entry to a certain number of characters. I know this is
easy in an original table, but I'm struggling because I did not limit in
the
past and don't want to corrupt the existing data. Can I allow a table to
store any amout of characters, but limit the characters that a form will
take
from this point forward?


You could use the text box's KeyPress event to check the current length of
the text. For example,

'------ start of example code ------
Private Sub Text0_KeyPress(KeyAscii As Integer)

Const conMaxChars = 10

Select Case KeyAscii
Case vbKeyReturn, vbKeyTab, vbKeyDelete, vbKeyBack
Case Else
With Me.Text0
If Len(.Text) >= conMaxChars Then
If .SelLength = 0 Then
MsgBox "Sorry, no more than " & conMaxChars & "
characters!"
KeyAscii = 0
End If
End If
End With
End Select

End Sub
'------ end of example code ------
 
Back
Top