Limite de texto en cuadro de texto

hola, quiero limitar a 500 los caracteres dentro de un cuadro de texto, cuando llegue a 500 que me salga un aviso diciendo que llego al limite.....buscando en internet encontré este código que me permite hacer el limite:
esto se pone a parte en el código:


Sub LimitFieldSize (KeyAscii, MAXLENGTH)
Dim C As Control
Dim CLen As Integer
Set C = Screen.ActiveControl
' Exit if a non-printable character is typed.
If KeyAscii < 32 Then Exit Sub
' Exit if typing replaces a selection.
If C.SelLength > 0 Then Exit Sub
' Fetch length of current contents + 1 for the character typed.
CLen = Len(C.Text & "") + 1
' Are there trailing spaces to contend with?
If C.SelStart + 1 > CLen Then CLen = C.SelStart + 1
' Is length of string greater than max?
If CLen > MAXLENGTH Then
Beep
KeyAscii = 0
End If
End Sub


y esto otro en el cuadro de texto, donde 50 es el limite


Sub (nombrecuadrotexto)_KeyPress (KeyAscii As Integer)
LimitFieldSize KeyAscii, 50
End Sub


este es el enlace:
http://support.microsoft.com/kb/152050/es


ahora bien, no logro hacer que me muestre el mensaje que deseo, se me ocurrió esto:
Private Sub texto2_KeyPress(KeyAscii As Integer)
LimitFieldSize KeyAscii, 500
If texto2 = 500 Then
MsgBox "Llego al limite de caracteres"
End If
End Sub
pero no funciona ¿que puedo hacer?

Añade tu respuesta

Haz clic para o