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
| 'Pour le bouton Nouveau contact à ajouter
Private Sub CommandButton1_Click()
Dim DernLig As Long
Dim num As Integer
If MsgBox("Confirmez-vous l'insertion de ce nouveau contact ?", vbYesNo, "Demande de confirmation d'ajout") = vbYes Then
With Sheets("CLIENTS")
'Pour placer le nouvel enregistrement à la première ligne de tableau non vide
'pour donner un numero client correspondant à la valeur la plus grande de la colonne A (CODE)+1
DernLig = .Range("A" & Rows.Count).End(xlUp).Row + 1
.Range("A" & DernLig).Value = WorksheetFunction.Max(.Range("A2:A" & DernLig)) + 1
.Range("B" & DernLig).Value = ComboBox1.Value 'nom entreprise
.Range("C" & DernLig).Value = TextBox2.Value 'nom
.Range("D" & DernLig).Value = TextBox3.Value 'prenom
.Range("E" & DernLig).Value = TextBox4.Value 'adresse
.Range("F" & DernLig).Value = TextBox5.Value 'cp
.Range("G" & DernLig).Value = TextBox6.Value 'ville
.Range("H" & DernLig).Value = TextBox7.Value 'telephone
.Range("I" & DernLig).Value = TextBox8.Value 'email
Unload UserForm1
End With
End If
End Sub
Private Sub CommandButton2_Click()
'Bouton MODIFIER un client
Dim modif As Integer
If Not ComboBox1.Value = "" Then
Sheets("CLIENTS").Select
modif = ComboBox1.ListIndex
Cells(modif, 1) = TextBox1.Value
Cells(modif, 2) = ComboBox1.Value
Cells(modif, 3) = TextBox2.Value
Cells(modif, 4) = TextBox3.Value
Cells(modif, 5) = TextBox4.Value
Cells(modif, 6) = TextBox5.Value
Cells(modif, 7) = TextBox6.Value
Cells(modif, 8) = TextBox7.Value
Cells(modif, 9) = TextBox8.Value
MsgBox ("Modification effectuée")
Else
MsgBox ("Veuillez sélectionner le client à modifier")
Exit Sub
End If
Unload UserForm1
'UserForm1.Show 0
End Sub
Private Sub CommandButton3_Click()
'Bouton rechercher
If Not ComboBox1.Value = "" Then
Dim no_ligne As Integer
no_ligne = ComboBox1.ListIndex + 3
TextBox1.Value = Cells(no_ligne, 1).Value
ComboBox1.Value = Cells(no_ligne, 2).Value
TextBox2.Value = Cells(no_ligne, 3).Value
TextBox3.Value = Cells(no_ligne, 4).Value
TextBox4.Value = Cells(no_ligne, 5).Value
TextBox5.Value = Cells(no_ligne, 6).Value
TextBox6.Value = Cells(no_ligne, 7).Value
TextBox7.Value = Cells(no_ligne, 8).Value
TextBox8.Value = Cells(no_ligne, 9).Value
Else
End If
End Sub |
Partager