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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
|
Option Explicit
Dim WS As Worksheet 'Variable pour un Objet Worksheet en PUBLIC pour tous les Controls de ce UserForm
Dim Nom As String 'Variable poyr récupérer l'ancienne valeur pour le Bouton Modif
Dim rgan As Range
Const T As String = "Base Clients"
Private Sub BOBOBOX_Change()
End Sub
Private Sub BoutQuitte_Click()
Unload Me
Feuil1.Activate
End Sub
Private Sub BOBOBOX_Click()
If Me.BOBOBOX.ListIndex = -1 Then Exit Sub 'ON sort si pas de sélection
Txt11 = WS.Range("B" & Me.BOBOBOX.ListIndex + 2) 'On alimente les données correspondant à la ligne
Txt12 = WS.Range("C" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt1 = WS.Range("D" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt2 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt3 = WS.Range("B" & Me.BOBOBOX.ListIndex + 2) 'On alimente les données correspondant à la ligne
Txt4 = WS.Range("C" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt5 = WS.Range("D" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt6 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt7 = WS.Range("B" & Me.BOBOBOX.ListIndex + 2) 'On alimente les données correspondant à la ligne
Txt8 = WS.Range("C" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt9 = WS.Range("D" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
Txt10 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
TextBox6 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
TextBox2 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
TextBox7 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
TextBox4 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
TextBox5 = WS.Range("E" & Me.BOBOBOX.ListIndex + 2) 'de l'index de la Combobox + 2 pour la ligne de Feuille
'ici on initialise les Variable pour mémoriser le valeur précédente en cas de Modif
With Me
Nom = .BOBOBOX
End With
End Sub
Private Sub CmdAjout_Click()
Dim CTRL As Control 'Variable pour la collection des controls
Dim L As Integer 'Variable pour connaitre le numéro de derniere ligne vide
Dim X As Integer, i As Integer 'Variables pour faire la boucle de checking de Duplication
Dim Response As Byte
Dim Match As Byte
L = WS.Range("A65536").End(xlUp).Row + 1 ' On identifie la dernière ligne vide en partant du bas
'ici un Control de Duplication
For X = 2 To L
If BOBOBOX = WS.Range("A" & X) Then
Match = Match + 1: i = X
End If
Next X
'Si il y a Duplication on demande en montrant les détails de la Duplication
If Match > 0 Then
Response = MsgBox("Duplication trouvée dans la Database pour : " & BOBOBOX & vbCrLf & _
"Nom : " & vbTab & vbTab & WS.Cells(i, 1) & vbCrLf & _
"Voulez-Vous Intégrer cet enregistrement ?", vbQuestion + vbOKCancel, T)
If Response = 1 Then
GoTo Suite 'On suit le déroulement si réponse OK
Else: GoTo Fin 'Sinon On sort
End If
End If
Suite:
'ici avec la Feuille on va faire :
With WS
.Range("A" & L) = BOBOBOX ' On écrit dans chaque colonne les valeurs des différents controls
.Range("B" & L) = Txt11 ' Idem
.Range("C" & L) = Txt12 ' Idem
.Range("D" & L) = Txt1
.Range("E" & L) = Txt2 ' Idem
.Range("f" & L) = Txt3 ' Idem
.Range("G" & L) = Txt4 ' Idem
.Range("H" & L) = Txt5
.Range("I" & L) = Txt6 ' Idem
.Range("J" & L) = Txt7 ' Idem
.Range("K" & L) = Txt8 ' Idem
.Range("L" & L) = Txt9
.Range("M" & L) = Txt10 ' Idem
.Range("N" & L) = TextBox3
.Range("O" & L) = TextBox6
.Range("P" & L) = TextBox2
.Range("Q" & L) = TextBox7
.Range("R" & L) = TextBox4
.Range("S" & L) = TextBox5
End With
Ini 'On lance la réinitialisation du UserForm (Macro en haut du Module)
Fin:
End Sub
Private Sub CmdEdit_Click()
Dim CTRL As Control 'Variable pour la collection des controls
Dim i As Integer
Dim Response As Byte
'Si le User tente de change le nom de la ComboBox en Mode Modification
If Me.BOBOBOX.ListIndex = -1 Then
Exit Sub 'ON sort si pas de sélection
End If
'Ici un message demandant d'accepter les changement en les listant
Response = MsgBox("Acceptez vous les changements ? ", vbQuestion + vbOKCancel, T & " Modification de : " & Nom)
'Si Réponse OK on continue
If Response = 1 Then
'ici avec la Feuille on va faire :
With WS
.Range("A" & Me.BOBOBOX.ListIndex + 2) = BOBOBOX ' On écrit dans chaque colonne les valeurs des différents controls
.Range("B" & Me.BOBOBOX.ListIndex + 2) = Txt11 ' Idem
.Range("C" & Me.BOBOBOX.ListIndex + 2) = Txt12 ' Idem
.Range("D" & Me.BOBOBOX.ListIndex + 2) = Txt1
.Range("E" & Me.BOBOBOX.ListIndex + 2) = Txt2 ' Idem
.Range("F" & Me.BOBOBOX.ListIndex + 2) = Txt3 ' Idem
.Range("G" & Me.BOBOBOX.ListIndex + 2) = Txt4 ' Idem
.Range("H" & Me.BOBOBOX.ListIndex + 2) = Txt5
.Range("I" & Me.BOBOBOX.ListIndex + 2) = Txt6 ' Idem
.Range("J" & Me.BOBOBOX.ListIndex + 2) = Txt7 ' Idem
.Range("K" & Me.BOBOBOX.ListIndex + 2) = Txt8 ' Idem
.Range("L" & Me.BOBOBOX.ListIndex + 2) = Txt9
.Range("M" & Me.BOBOBOX.ListIndex + 2) = TextBox3 ' Idem
.Range("N" & Me.BOBOBOX.ListIndex + 2) = TextBox6
.Range("O" & Me.BOBOBOX.ListIndex + 2) = TextBox2
.Range("P" & Me.BOBOBOX.ListIndex + 2) = TextBox7
.Range("Q" & Me.BOBOBOX.ListIndex + 2) = TextBox4
.Range("R" & Me.BOBOBOX.ListIndex + 2) = TextBox5
End With 'On evoie un message de confirmation
MsgBox "Opération accomplie", vbInformation, T
Ini 'On lance la réinitialisation du UserForm (Macro en haut du Module)
'Si Réponse Annulation on envoie un message et on a rien fait
Else: MsgBox "Opération annulée", vbInformation, T
End If
End Sub
Private Sub CmdSup_Click()
Dim CTRL As Control 'Variable pour la collection des controls
Dim i As Integer
Dim Response As Byte
If Me.BOBOBOX.ListIndex = -1 Then Exit Sub
'Ici un message demandant d'accepter la suppression en les listant
Response = MsgBox("Les coordonnées de " & vbCrLf & vbCrLf & _
"Nom : " & vbTab & vbTab & BOBOBOX & vbCrLf & vbCrLf & _
"Vont être définitivement Supprimées ? ", vbCritical + vbOKCancel, T)
'Si Réponse OK on continue
If Response = 1 Then
'ici avec la Feuille on va faire :
With WS
.Rows(Me.BOBOBOX.ListIndex + 2).EntireRow.Delete
End With
'On evoie un message de confirmation
MsgBox "Opération accomplie", vbInformation, T
Ini 'On lance la réinitialisation du UserForm (Macro en haut du Module)
'Si Réponse Annulation on envoie un message et on a rien fait
Else: MsgBox "Opération annulée", vbInformation, T
End If
End Sub
Private Sub CommandButton1_Click()
Ini
End Sub
Private Sub Label39_Click()
End Sub
Private Sub TextBox2_Change()
End Sub
Private Sub TextBox3_Change()
End Sub
Private Sub TextBox4_Change()
End Sub
Private Sub TextBox6_Change()
End Sub
Private Sub TextBox7_Change()
End Sub
Private Sub Txt1_Change()
End Sub
Private Sub Txt11_Change()
End Sub
Private Sub Txt3_Change()
End Sub
Private Sub Txt5_Change()
End Sub
Private Sub Txt7_Change()
End Sub
Private Sub Txt8_Change()
End Sub
Private Sub UserForm_Initialize()
With BOBOBOX
BOBOBOX.AddItem "Ingrédients"
BOBOBOX.AddItem "Emballages"
BOBOBOX.AddItem "Techniques"
End With
End Sub
Private Sub Ini()
Dim CTRL As Control 'Variable pour la collection des controls
Dim L As Integer 'Variable pour connaitre le numéro de derniere ligne
Dim i As Integer 'Variable pour connaitre incrémenter les Data
'On Vide tous les Controls
For Each CTRL In Me.Controls
If TypeOf CTRL Is MSForms.TextBox Or TypeOf CTRL Is MSForms.ComboBox Then
CTRL = ""
End If
Next CTRL
Me.BOBOBOX.Clear 'On vide les précédentes données
Set WS = ThisWorkbook.Sheets("Base") 'On identifie l'objet pour la feuille de travail
L = WS.Range("A65536").End(xlUp).Row 'On identifie la dernière ligne en partant du bas
'Pour éviter les fash d'écran pour le select ci dessous
Application.ScreenUpdating = False
WS.Select 'On sélectionne la feuille sinon bug si elle ne l'est pas
WS.Range("A6").Sort Key1:=Range("A6"), Order1:=xlAscending, Header:=xlGuess 'Le Sort
For i = 2 To L 'Boucle départ 2 (Ligne 2 de la feuille, jusqu'à dernière
Next i 'Next pour poursuivre la boucle pour le i suivant
Application.ScreenUpdating = True
End Sub |
Partager