Bonjour au forum,

Voilà, j'ai 2problèmes dans mon suserform
- le premier concerne textbox et case à cocher
lorsque l'userform s'affiche verifie que la TextBox18 soit remplie, si oui la checkbox est cochée si non alors logique c'est l'inverse et TextBox18 encadrée en rouge. Ce que j'écris dans UserForm_Initialize()
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
If Me.TextBox18 = "" Then
CheckBox1 = False
Me.TextBox18 .BorderColor = RGB(255, 0, 0)
If Me.TextBox18 <> "" Then
Else: CheckBox1 = True
End If
End If
Le problème, c'est que ça reste cocher même si TextBox18 est remplie, comment faire ?

- le deuxième problème est le controle de doublon
Je saisie dans mon formulaire (qui s'ouvre depuis un bouton d'un autre formulaire)
le nom puis le nom de l'entreprise etc., si TxtNom ou TxtEntreprise existe, il affiche un message sinon je peux continuer à remplir le reste du formulaire. Ca marche en partie
Le code de l'userform pour etre plus claire.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
Option Explicit
 
Private Sub TxtNom_Change()
If TxtNom = "" Then VérifExistence
'End If
End Sub
 
Private Sub TxtEntreprise_Change()
If TxtEntreprise= "" Then VérifExistence
'End If
End Sub
 
Private Sub CommandButton1_Click()
Dim r, Y As Long
Dim ob As Control
If TextBox18  = "" Then
MsgBox "Merci de compléter le nom du nouveau client avant de saisir les autres données !"
Me.TextBox18 .BorderColor = vbRed 'RGB(255, 0, 0)
TextBox18 .SetFocus
Exit Sub
End If
For Each ob In Me.Controls
If ob.Tag > "" Then
Select Case Val(ob.Tag)
Case 16, 17, 1
Feuil9.Cells(gg, Val(ob.Tag)) = Val(ob)
'Case 16
'If ob.Value = True Then Feuil9.Cells(gg, Val(ob.Tag)) = 1 Else Feuil9.Cells(gg, Val(ob.Tag)) = 0
Case 31, 23
If IsDate(ob) = True Then Feuil9.Cells(gg, Val(ob.Tag)) = CDate(ob) Else Feuil9.Cells(gg, Val(ob.Tag)) = ""
Case Else
Feuil9.Cells(gg, Val(ob.Tag)) = ob
End Select
End If
Next
dico1
dep.client.Clear
If dep.TextBox9 = "" Then
For r = 2 To finf9
dep.client.AddItem Feuil9.Cells(r, 1) & " " & Feuil9.Cells(r, 3) & " (" & Feuil9.Cells(r, 4) & ")"
dep.client.List(r - 2, 1) = r
Next
dep.client = gg
Else
For r = 2 To finf9
If UCase(Mid(Feuil9.Cells(r, 3), 1, Len(dep.TextBox9))) = UCase(dep.TextBox9) Then
dep.client.AddItem Feuil9.Cells(r, 1) & " " & Feuil9.Cells(r, 3) & " (" & Feuil9.Cells(r, 4) & ")"
dep.client.List(Y, 1) = r
Y = Y + 1
End If
Next
End If
Unload Me
End Sub
 
Private Sub UserForm_activate()
Dim ob As Control
For Each ob In Me.Controls
If ob.Tag > "" Then
Select Case Val(ob.Tag)
Case 16, 17
ob = Format(Feuil9.Cells(gg, Val(ob.Tag)), "0.00")
ob = Replace(ob, ",", ".")
Case Else
ob = Feuil9.Cells(gg, Val(ob.Tag))
End Select
End If
Next
If nom = "" Then nom = WorksheetFunction.Max(Feuil9.Range("a:a")) + 1
End Sub
 
Private Sub UserForm_Initialize()
Dim aa
plus
aa = Feuil18.Range("a2:a" & Feuil18.Range("a6500").End(xlUp).Row)
ComboBox1.List = aa
aa = Feuil18.Range("b2:b" & Feuil18.Range("b6500").End(xlUp).Row)
ComboBox2.List = aa
aa = Feuil18.Range("c2:c" & Feuil18.Range("c6500").End(xlUp).Row)
ComboBox3.List = aa
'aa = Feuil18.Range("d2:d" & Feuil18.Range("d6500").End(xlUp).Row)
'ComboBox4.List = aa
aa = Feuil18.Range("e2:e" & Feuil18.Range("e6500").End(xlUp).Row)
ComboBox5.List = aa
aa = Feuil18.Range("g2:g" & Feuil18.Range("g6500").End(xlUp).Row)
ComboBox6.List = aa
aa = Feuil18.Range("h2:h" & Feuil18.Range("h6500").End(xlUp).Row)
ComboBox7.List = aa
aa = Feuil18.Range("i2:i" & Feuil18.Range("i6500").End(xlUp).Row)
ComboBox8.List = aa
aa = Feuil18.Range("f2:f" & Feuil18.Range("f6500").End(xlUp).Row)
ComboBox9.List = aa
aa = Feuil18.Range("k2:k" & Feuil18.Range("k6500").End(xlUp).Row)
ComboBox10.List = aa
aa = Feuil18.Range("j2:j" & Feuil18.Range("j6500").End(xlUp).Row)
ComboBox11.List = aa
 
If Me.TextBox18 = "" Then
CheckBox1 = False
Me.TextBox18 .BorderColor = vbRed 'RGB(255, 0, 0)
If Me.TextBox18 <> "" Then
Else: CheckBox1 = True
End If
End If
End Sub
 
Private Sub VérifExistence()
 Dim TV() As Variant, L As Long
 TV = Feuil9.[C:D].Value
 L = 1
 Do: L = L + 1
    If TV(L, 1) = "" And TV(L, 2) = "" Then Exit Sub
    If TV(L, 1) = TxtNom  And TV(L, 2) = TxtEntreprise Then Exit Do
    Loop
 MsgBox TxtNom  & " " & TxtEntreprise & " existe déjà"
 End Sub
Qu'est-ce qui ne vas pas ?

Merci Stephanie