Private Sub Textbox1_Change()
TextBox1.BackColor = &H80000005
End Sub
Private Sub Textbox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
TextBox1.BackColor = &H80000005
If InStr("0123456789", VBA.Chr(KeyAscii)) = 0 Then
KeyAscii = 0
TextBox1.BackColor = &HFF&
End If
End Sub
Private Sub Textbox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(TextBox1.Text) = 0 Then
GoTo Fin
End If
If Len(Replace(TextBox1.Text, "/", "")) <> 6 And Len(Replace(TextBox1.Text, "/", "")) <> 8 Then
GoTo ErreurSaisie
End If
If Len(TextBox1.Text) = 6 Then
If Right(TextBox1, 2) > 50 Then
TextBox1 = Left(TextBox1, 4) & 19 & Right(TextBox1, 2)
Else
TextBox1 = Left(TextBox1, 4) & 20 & Right(TextBox1, 2)
End If
End If
TextBox1.Text = Left(Replace(TextBox1.Text, "/", ""), 2) & "/" & Mid(Replace(TextBox1.Text, "/", ""), 3, 2) & "/" & Right(Replace(TextBox1.Text, "/", ""), 4)
TextBox1.MaxLength = 10
If Not IsDate(TextBox1.Value) Then
GoTo ErreurSaisie
End If
GoTo Fin
ErreurSaisie:
Cancel = True
With TextBox1
.BackColor = &HFF&
MsgBox "Date saisie incorrecte"
TextBox1.Text = Replace(TextBox1.Text, "/", "")
.SetFocus
.SelStart = 0
.SelLength = Len(TextBox1.Text)
End With
Fin:
End Sub
Private Sub NSaisie8_Enter()
NSaisie8.Text = Replace(NSaisie8.Text, "/", "")
NSaisie8.MaxLength = 8
End Sub