Private Sub TextBox6_Change()
'Renseignement N° ODM
Dim prefixe$
couleur = Array(vbYellow, vbRed)
With TextBox6
.BackColor = couleur(Abs(Not .BackColor = vbRed))
prefixe = "ODM-"
.Value = Mid(.Value, 1, 9)
If Mid(.Value, 1, Len(prefixe)) <> prefixe Then .Value = prefixe
If Not IsNumeric(Mid(.Value, Len(prefixe) + 1)) Then .Value = prefixe
If Len(.Value) >= 9 Then .BackColor = vbGreen
End With
CommandButton5.Enabled = TextBox1 <> "" And TextBox2 <> "" And TextBox4 <> "" And TextBox5 <> "" And Len(TextBox6) = 9 And TextBox7 <> "" And TextBox8 <> "" And Len(TextBox10) = 3
End Sub
Bonsoir le forum
Bonsoir PETIT YANNICK, bonsoir patricktoulon
@patrick : Concernant le CommandButton5.Enabled , ne peut-on exécuter une boucle sur les TextBoxs (suite non logique car 1,2,4,5,6,7,8 & 10) avec un "ARRAY" par exemple car le nombre ici est de 8 TextBoxs mais s'il y en avait 15,20 voire plus ????
@+ Eric c
bonjour
pour ton textbox6
VB:Private Sub TextBox6_Change() 'Renseignement N° ODM Dim prefixe$ couleur = Array(vbYellow, vbRed) With TextBox6 .BackColor = couleur(Abs(Not .BackColor = vbRed)) prefixe = "ODM-" .Value = Mid(.Value, 1, 9) If Mid(.Value, 1, Len(prefixe)) <> prefixe Then .Value = prefixe If Not IsNumeric(Mid(.Value, Len(prefixe) + 1)) Then .Value = prefixe If Len(.Value) >= 9 Then .BackColor = vbGreen End With CommandButton5.Enabled = TextBox1 <> "" And TextBox2 <> "" And TextBox4 <> "" And TextBox5 <> "" And Len(TextBox6) = 9 And TextBox7 <> "" And TextBox8 <> "" And Len(TextBox10) = 3 End Sub
Private Sub TextBox6_Change()
'Renseignement N° ODM
Dim prefixe$
couleur = Array(vbYellow, vbRed)
With TextBox6
Me.Label6.ForeColor = couleur(Abs(Not Label6.ForeColor = vbRed))
prefixe = "ODM-"
.Value = Mid(.Value, 1, 9)
If Mid(.Value, 1, Len(prefixe)) <> prefixe Then .Value = prefixe
If Not IsNumeric(Mid(.Value, Len(prefixe) + 1)) Then .Value = prefixe
If Len(.Value) >= 9 Then Me.Label6.ForeColor = vbGreen
End With
CommandButton5.Enabled = TextBox1 <> "" And TextBox2 <> "" And TextBox4 <> "" And TextBox5 <> "" And Len(TextBox6) = 9 And TextBox7 <> "" And TextBox8 <> "" And Len(TextBox10) = 3
End Sub
Sub Lancer_formulaire()
UserForm1.Show vbModeless
Clignote 'lance le processus
End Sub
Sub Clignote()
Static t 'mémorise la variable
On Error Resume Next
Application.OnTime t, "Clignote", , False
If UserForms.Count = 0 Then Exit Sub
t = Now + 1 / 86400 'demi-période 1 seconde
Application.OnTime t, "Clignote"
With UserForm1
If Len(.TextBox6) < 9 Then .Label27.Visible = Not .Label27.Visible: .TextBox6.SetFocus
End With
End Sub
Private Sub TextBox6_Change()
Dim x$, i%
x = TextBox6
x = "ODM-" & Replace(x, "ODM-", "")
For i = Len(x) To 5 Step -1
If Not IsNumeric(Mid(x, i, 1)) Then x = Left(x, i - 1) & Mid(x, i + 1)
Next
TextBox6 = x
End Sub
Sub Lancer_formulaire()
UserForm1.Show vbModeless
Clignote 'lance le processus
End Sub
Sub Clignote()
Dim t
With UserForm1
Do While UserForms.Count
DoEvents
If Len(.TextBox6) < 9 Then
.Label27.Visible = Not .Label27.Visible
.TextBox6.SetFocus
t = Timer + 0.5 'demi-période de 0,5 seconde
While Timer < t And t < 86400: DoEvents:: Wend
End If
Loop
End With
End Sub
CommandButton5.Enabled = TextBox1 <> "" And TextBox2 <> "" And TextBox4 <> "" And TextBox5 <> "" And TextBox7 <> "" And TextBox8 <> ""
Et pourquoi donc ?Je n ai pas put essayer le fichier que vous avez fournis.
Fichier (3) avec :Comment dois je procéder pour faire clignoter également le label26 quand je saisies la textbox 10?
Sub Clignote()
Dim t
With UserForm1
Do While UserForms.Count
t = Timer + 0.5 'demi-période de 0,5 seconde
While Timer < t And t < 86400: DoEvents:: Wend
If Len(.TextBox6) < 9 Then .Label27.Visible = Not .Label27.Visible
If Len(.TextBox10) < 3 Then .Label26.Visible = Not .Label26.Visible
Loop
End With
End Sub
CommandButton5.Enabled = TextBox1 <> "" And TextBox2 <> "" And TextBox4 <> "" And TextBox5 <> "" And Len(TextBox6) = 9 And TextBox7 <> "" And TextBox8 <> "" And Len(TextBox10) = 3
Sub VérifRemplissage()
Dim i As Byte
For i = 1 To 5
If Controls("TextBox" & i).Value = "" Then
CommandButton1.Enabled = False
Exit Sub
End If
Next i
CommandButton1.Enabled = True
End Sub
Private Sub TextBox1_change()
VérifRemplissage
End Sub
Private Sub TextBox2_change()
VérifRemplissage
End Sub
Private Sub TextBox3_change()
VérifRemplissage
End Sub
Private Sub TextBox4_change()
VérifRemplissage
End Sub
Private Sub TextBox5_change()
VérifRemplissage
End Sub
Il est vraiment simplifié et il n'y a aucun intérêt à faire une boucle.Certe, le code est simplifié, semble t'il mais ne peut on pas "boucler" sur des TextBoxs qui ne se suivent pas ?[/CODE]