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
| Private Sub TextBox1_Change()
Static javais As String
javais = gendarme("/", javais)
Me.ActiveControl.Text = javais
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Len(Me.ActiveControl.Text) Mod 10 <> 0 Then MsgBox "ouille": Cancel = True
End Sub
Private Function gendarme(sep As String, chaine As String) As String
gendarme = chaine
Dim toto As String
toto = Me.ActiveControl.Text
Me.ActiveControl.SelStart = Len(toto)
If Me.ActiveControl.SelStart < Len(Me.ActiveControl.Text) Then
Me.ActiveControl.SelStart = Len(Me.ActiveControl.Text)
Exit Function
End If
If Not toto Like Left("##" & sep & "##" & sep & "####", Len(toto)) Then Exit Function
Dim refer As String
If Len(toto) < 4 Or Mid(toto, 4, 1) <> 0 Then
refer = toto & Mid("01/10/2000", Len(toto) + 1)
Else
refer = toto & Mid("01/03/2000", Len(toto) + 1)
End If
If Not IsDate(refer) Then Exit Function
If Len(toto) = 4 And Val(Mid(toto, 4, 1)) > 1 Then Exit Function
If Len(toto) = 5 And Val(Mid(toto, 4, 2)) > 12 Then Exit Function
gendarme = Me.ActiveControl.Text
If (Len(gendarme) = 2 Or Len(gendarme) = 5) And Len(toto) > Len(chaine) Then
gendarme = gendarme & sep
End If
End Function |