Ingresar solo números en TextBox con formato de fecha
Publicado por Juan (200 intervenciones) el 17/11/2022 16:07:59
Tengo un formulario con un TextBox para ingresar fecha. Solo digito números porque el guion se coloca automáticamente. El problema se presenta cuando quiero borrar carácter por carácter de derecha a izquierda no me deja por el guion. ¿Cómo podría modificar el código para que permita borrar de esa forma?
Private Sub TextBox1_Change()
If Bandera = False Then
If Len(ActiveControl) > 10 Then
ActiveControl = Mid(ActiveControl, 1, 10)
MsgBox "lA fEcHa eStA CoMpLeTa"
Else
If Len(ActiveControl) = 2 Then
ActiveControl = ActiveControl & "-"
End If
If Len(ActiveControl) = 5 Then
ActiveControl = ActiveControl & "-"
End If
End If
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 50 Then
Bandera = True
Else
Bandera = False
End If
End Sub
Private Sub TextBox1_Change()
If Bandera = False Then
If Len(ActiveControl) > 10 Then
ActiveControl = Mid(ActiveControl, 1, 10)
MsgBox "lA fEcHa eStA CoMpLeTa"
Else
If Len(ActiveControl) = 2 Then
ActiveControl = ActiveControl & "-"
End If
If Len(ActiveControl) = 5 Then
ActiveControl = ActiveControl & "-"
End If
End If
End If
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 50 Then
Bandera = True
Else
Bandera = False
End If
End Sub
- Libro1.zip(10,8 KB)
Valora esta pregunta


0