Bonjour @ tous,
je viens vous demander un petit coup de main,
je cherche à faire une fonction automatique de contrôle de la date pour toutes mes textbox avec comme base:
Function controledate()
If TextBox1.Value = "" Then TextBox1.Value = Date
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 function
Je l'ai fait avec textbox 1 mais j'aimerais qu'il me fasse la même chose quelque soit ma textbox en utilisant dans l'userform:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
controledate
End Sub
D'avance merci
je viens vous demander un petit coup de main,
je cherche à faire une fonction automatique de contrôle de la date pour toutes mes textbox avec comme base:
Function controledate()
If TextBox1.Value = "" Then TextBox1.Value = Date
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 function
Je l'ai fait avec textbox 1 mais j'aimerais qu'il me fasse la même chose quelque soit ma textbox en utilisant dans l'userform:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
controledate
End Sub
D'avance merci