1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| Private Sub txtdate1_Change()
txtdate.BackColor = &H80000005
End Sub
Private Sub txtdate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
txtdate.BackColor = &H80000005
If InStr("0123456789", VBA.Chr(KeyAscii)) = 0 Then
KeyAscii = 0
txtdate.BackColor = &HFF&
End If
End Sub
Private Sub txtdate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(txtdate.Text) = 0 Then
GoTo Fin
End If
If Len(Replace(txtdate.Text, "/", "")) <> 6 And Len(Replace(txtdate.Text, "/", "")) <> 8 Then
GoTo ErreurSaisie
End If
If Len(txtdate.Text) = 6 Then
If Right(txtdate, 2) > 50 Then
txtdate = Left(txtdate, 4) & 19 & Right(TextBox1, 2)
Else
txtdate = Left(txtdate, 4) & 20 & Right(TextBox1, 2)
End If
End If
txtdate.Text = Left(Replace(txtdate.Text, "/", ""), 2) & "/" & Mid(Replace(txtdate.Text, "/", ""), 3, 2) & "/" & Right(Replace(txtdate.Text, "/", ""), 4)
txtdate.MaxLength = 10
If Not IsDate(txtdate.Value) Then
GoTo ErreurSaisie
End If
GoTo Fin
ErreurSaisie:
Cancel = True
With txtdate
.BackColor = &HFF&
MsgBox "Date saisie incorrecte"
txtdate.Text = Replace(txtdate.Text, "/", "")
.SetFocus
.SelStart = 0
.SelLength = Len(txtdate.Text)
End With
Fin:
End Sub |
Partager