Private Sub DateBox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(DateBox.Text) = 0 Then
GoTo Fin
End If
If Len(Replace(DateBox.Text, "/", "")) <> 6 And Len(Replace(DateBox.Text, "/", "")) <> 8 Then
GoTo ErreurSaisie
End If
If Len(DateBox.Text) = 6 Then
If Right(DateBox, 2) > 50 Then
DateBox = Left(DateBox, 4) & 19 & Right(DateBox, 2)
Else
DateBox = Left(DateBox, 4) & 20 & Right(DateBox, 2)
End If
End If
DateBox.Text = Left(Replace(DateBox.Text, "/", ""), 2) & "/" & Mid(Replace(DateBox.Text, "/", ""), 3, 2) & "/" & Right(Replace(DateBox.Text, "/", ""), 4)
DateBox.MaxLength = 10
If Not IsDate(DateBox.Value) Then
GoTo ErreurSaisie
End If
[COLOR="red"]
aa = Format(Month(DateBox), "00") & Right(Year(DateBox), 2)
If Right(Feuil1.[J65536].End(3), 4) = aa Then
LabelNo = Feuil1.[J65536].End(3) + 1
Else
LabelNo = "01" & aa
End If
[/COLOR]
GoTo Fin
ErreurSaisie:
Cancel = True
With DateBox
.BackColor = &HFF&
MsgBox "Date saisie incorrecte"
DateBox.Text = Replace(DateBox.Text, "/", "")
.SetFocus
.SelStart = 0
.SelLength = Len(DateBox.Text)
End With
Fin:
End Sub