Private Sub TextBox1_Change() If Len(TextBox1.Text) = 2 Then If Val(TextBox1.Text) > 31 Or Val(TextBox1.Text) < 1 Or IsNumeric(TextBox1.Text) = False Then TextBox1.Text = "" Else TextBox1.Text = TextBox1.Text & "/" End If End If If Len(TextBox1.Text) = 5 Then If Val(Right(TextBox1.Text, 2)) > 31 Or Val(Right(TextBox1.Text, 2)) < 1 Or IsNumeric(Right(TextBox1.Text, 2)) = False Then TextBox1.Text = Left(TextBox1.Text, 3) Else TextBox1.Text = TextBox1.Text & "/" End If End If End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If IsNumeric(Chr(KeyAscii)) False Or Len(TextBox1.Text) > 9 Then KeyAscii 0 End Sub 'Dans ce cas l'utilisateur est forcé à entrer des valeurs au format "/0x/" et non "/x/"
Dim Deleting As Boolean Private Sub TextBox1_Change() If Deleting = False Then If Len(TextBox1.Text) = 2 Then If Val(TextBox1.Text) > 31 Or Val(TextBox1.Text) < 1 Or IsNumeric(TextBox1.Text) = False Then TextBox1.Text = "" Else TextBox1.Text = TextBox1.Text & "/" End If End If If Len(TextBox1.Text) = 5 Then If Val(Right(TextBox1.Text, 2)) > 31 Or Val(Right(TextBox1.Text, 2)) < 1 Or IsNumeric(Right(TextBox1.Text, 2)) = False Then TextBox1.Text = Left(TextBox1.Text, 3) Else TextBox1.Text = TextBox1.Text & "/" End If End If End If End Sub Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 8 Then Deleting = True Else Deleting = False End If End Sub Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) If IsNumeric(Chr(KeyAscii)) False Or Len(TextBox1.Text) > 9 Then KeyAscii 0 End Sub 'Dans ce cas l'utilisateur est forcé à entrer des valeurs au format "/0x/" et non "/x/"
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question