Character Limits

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?
 
D

Dirk Goldgar

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 ------
 

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

Top