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
Option Compare Text
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
Private Sub textTEL_Change() 'mise en forme de 6 telephones
Dim T$, mem$
T = Mid(textTEL.Text, 1, 15) 'passer de 14 à 15 pour les internationaux 33,34,etc...
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 & " " 'on peut mettre un point entre les ""
textTEL = T
textTEL.Tag = textTEL.Text
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 textLettre_Change()
End Sub
''donc dans les tag des textboxs tu mettra selon le type que tu veux "date","tel" ou "lettre"
et donc selon le type je corrige le keyascii dans le keypress