Hola bueno ise una aplicacion donde ocupo que un text box solo admita numeros por que si no truena tengo este codigo:
Sub Text2_Keypress(KeyAscii As Integer)
If KeyAscii <> Asc("9") Then
If KeyAscii <> 8 Then
KeyAscii = 0
End If
End If
End Sub
pero solo deja poner el 9 y no los demas numeros no se donde la estoy regando no se si tu me puedas ayudar.
De antemano gracias
Bueno gracias ya tengo el codigo
era este:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
O asi:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 47 Or KeyAscii > 57 Then
If KeyAscii <> 8 Then KeyAscii = 0
End If
End Sub
Private Sub txtData_LostFocus()
If Not IsNumeric(txtData) Then
Call MsgBox("Tenés que ingresar un valor numérico", vbExclamation)
txtData = vbNullString
End If
End Sub
o
Private Sub txtNum_Validate(Cancel As Boolean)
If Not IsNumeric(txtData) Then
Call MsgBox("Tenés que ingresar un valor numérico", vbExclamation)
txtData = vbNullString
Cancel = True
End If
End Sub
Slasher-K y
Hwagm
Gracias.
Hola, prueba con esto:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0 ' Para que no "pite"
SendKeys "{tab}" ' Envía una pulsación TAB
ElseIf KeyAscii <> 8 Then ' El 8 es la tecla de borrar (backspace)
' Si después de añadirle la tecla actual no es un número...
'If Not IsNumeric("0" & Text1.Text & Chr(KeyAscii)) Then
If Not IsNumeric(Chr(KeyAscii)) Then ' ... se desecha esa tecla y se avisa de que no es correcta Beep
KeyAscii = 0
End If End If
End Sub
Salu2