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
| Public WithEvents textDate As MSForms.TextBox
Public WithEvents textTEL As MSForms.TextBox
Public WithEvents textLettre As MSForms.TextBox
Public usf As Object
Dim cls() As New specialtextbox
Function initiate(uf)
For Each ctrl In uf.Controls
If ctrl.Tag = "date" Then i = i + 1: ReDim Preserve cls(1 To i): Set cls(i).textDate = ctrl: ctrl.Tag = "": Set usf = uf
If ctrl.Tag = "tel" Then i = i + 1: ReDim Preserve cls(1 To i): Set cls(i).textTEL = ctrl: ctrl.Tag = "": Set usf = uf
If ctrl.Tag = "lettre" Then i = i + 1: ReDim Preserve cls(1 To i): Set cls(i).textLettre = ctrl: ctrl.Tag = "": Set usf = uf
Next
End Function
'on bloque les numerique ou les lettres selon le type de textbox
Private Sub textDate_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger): KeyAscii = IIf(Not Chr(KeyAscii) Like "[0-9/]", 0, KeyAscii): End Sub
Private Sub textTEL_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger): KeyAscii = IIf(Not Chr(KeyAscii) Like "[0-9 ]", 0, KeyAscii): End Sub
Private Sub textLettre_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger): KeyAscii = IIf(IsNumeric(Chr(KeyAscii)), 0, KeyAscii): End Sub
'les contrainte dans les evenement pour chaque type de textbox
Private Sub textDate_Change()
Dim T$
T = Mid(textDate.Text, 1, 10)
If Mid(T, 1, 1) > 3 Then T = ""
If Len(T) = 2 And Val(T) > 31 Then T = Mid(T, 1, 1)
If Len(T) >= 3 And Mid(T, 3, 1) <> "/" Then T = Mid(T, 1, 2)
If Len(T) >= 4 And Val(Mid(T, 4, 1)) > 1 Then T = Mid(T, 1, 3)
If Len(T) >= 5 And Val(Mid(T, 4, 2)) > 12 Then T = Mid(T, 1, 4)
If Len(T) >= 6 And Mid(T, 6, 1) <> "/" Then T = Mid(T, 1, 5)
If Len(T) = 10 And Not IsDate(T) Then MsgBox T & vbCrLf & "la date entrée n'est pas valide" & vbCrLf & "veuillez recommencer": T = "":
textDate = T
End Sub
Private Sub textTEL_Change()
Dim T$, mem$
T = Mid(textTEL.Text, 1, 14)
mem = textTEL.Tag
If (Len(T) = 2 Or Len(T) = 5 Or Len(T) = 8 Or Len(T) = 11) And Len(mem) < Len(T) Then T = T & " "
textTEL = T
textTEL.Tag = textTEL.Text
End Sub
Private Sub textLettre_Change()
End Sub |
Partager