Private Sub CommandButton_Ajouter_Click()
'Coloration des Labels en noir
Label_Nom.ForeColor = RGB(0, 0, 0)
Label_Prenom.ForeColor = RGB(0, 0, 0)
Label_Adresse.ForeColor = RGB(0, 0, 0)
Label_Lieu.ForeColor = RGB(0, 0, 0)
Label_Pays.ForeColor = RGB(0, 0, 0)
'Contrôles de contenu
If TextBox_Nom.Value = "" Then 'SI pas de "nom" ...
Label_Nom.ForeColor = RGB(255, 0, 0) 'Label "nom" en rouge
ElseIf TextBox_Prenom.Value = "" Then
Label_Prenom.ForeColor = RGB(255, 0, 0)
ElseIf TextBox_Adresse.Value = "" Then
Label_Adresse.ForeColor = RGB(255, 0, 0)
ElseIf TextBox_Lieu.Value = "" Then
Label_Lieu.ForeColor = RGB(255, 0, 0)
ElseIf ComboBox_Pays.Value = "" Then
Label_Pays.ForeColor = RGB(255, 0, 0)
Else
'Si le formulaire est complet, on insère les valeurs sur la feuille
Dim no_ligne As Integer, civilite As String
'Choix de civilité
For Each bouton_civilite In Frame_Civilite.Controls
If bouton_civilite.Value Then
civilite = bouton_civilite.Caption
End If
Next
'no_ligne = N° de ligne de la dernière cellule non vide de la colonne +1
no_ligne = Range("A65536").End(xlUp).Row + 1
'Insertion des valeurs sur la feuille
Cells(no_ligne, 1) = civilite
Cells(no_ligne, 2) = TextBox_Nom.Value
Cells(no_ligne, 3) = TextBox_Prenom.Value
Cells(no_ligne, 4) = TextBox_Adresse.Value
Cells(no_ligne, 5) = TextBox_Lieu.Value
Cells(no_ligne, 6) = ComboBox_Pays.Value
If ComboBox_Pays.ListIndex = -1 Then
Sheets("Pays").Range("A" & Sheets("Pays").Range("A65536").End(xlUp).Row + 1) = Me.ComboBox_Pays
Me.ComboBox_Pays.AddItem Me.ComboBox_Pays
End If
'Après insertion, on remet les valeurs initiales
OptionButton1.Value = True
TextBox_Nom.Value = ""
TextBox_Prenom.Value = ""
TextBox_Adresse.Value = ""
TextBox_Lieu.Value = ""
ComboBox_Pays.ListIndex = -1
End If
End Sub