Access - limite de texto en cuadro de texto

 
Vista:
sin imagen de perfil

limite de texto en cuadro de texto

Publicado por jose maria (89 intervenciones) el 24/06/2013 09:57:03
hola, quiero limitar a 500 los caracteres dentro de un cuadro de texto, cuando llege a 500 que me salga un aviso diciendo que llego al limite.....buscando en internet encontre este codigo que me permite hacer el limite:

esto se pone a parte en el codigo:

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 ocurrio 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?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Neckkito
Val: 529
Plata
Ha mantenido su posición en Access (en relación al último mes)
Gráfica de Access

limite de texto en cuadro de texto

Publicado por Neckkito (1157 intervenciones) el 24/06/2013 14:19:19
Hola!

El código de tu KeyPress del texto2 sólo debería decir:

...
Private Sub texto2_KeyPress(KeyAscii As Integer)
LimitFieldSize KeyAscii, 500
End Sub
...

Y en el sub tienes que cambiar la línea del beep por tu mensaje. Es decir (te pongo algunas líneas anteriores y posteriores para que te sitúes):
...
'Todo el código anterior del sub
' Is length of string greater than max?
If CLen > MAXLENGTH Then
MsgBox "Llego al limite de caracteres"
KeyAscii = 0
End If
...

A ver si así te funciona.

Un saludo,


http://neckkito.siliconproject.com.ar
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

limite de texto en cuadro de texto

Publicado por jose maria (89 intervenciones) el 25/06/2013 09:09:11
hola, funciono, de echo, deje tambien la linea de beep, el msgbox lo puse debajo
gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar