Sub BDELEVE()
'This is a new line. At least one field should be required, I picked up C11
'you can chose another cell but that cell's info will be the one to find the last row in DB
'so, make it match with this line: LastRow = Sheets("D_Base").Range("C" & Rows.Count).End(xlUp).Row + 1
If Sheets("F_Élève").Range("C11").Value = "" Then MsgBox "ECOLE is required, please enter some data in C11", vbExclamation, "Missing Info...": Exit Sub
'you can add more required fields here
''''''''''''''''''''''''''''''''''''''
'Those variables will be treated as string, including the date (this can be changed if you want)
Dim ECOLE, ADRESSE, VILLE, TELEPHONE, NOM, PRENOM, AGE, NIVEAU, VDATE1, HEURE, LIEU, SURVEILLANCE, ACCIDENT, BLESSURE, Actions, COMMENTAIRES, TEMOIN1, VDATET1, TEMOIN2, VDATET2, RESPONSABLE, VDATER, Direction, VDATED, MARSH
'this variable is to find the last row with data in the DB sheet
Dim LastRow As Integer
'Here you retreive the data in the form (I don't know in what cells they are, but make the changes)
ECOLE = Sheets("F_Élève").Range("C11").Value
ADRESSE = Sheets("F_Élève").Range("C13").Value
VILLE = Sheets("F_Élève").Range("F11").Value
TELEPHONE = Sheets("F_Élève").Range("F13").Value
NOM = Sheets("F_Élève").Range("C17").Value
PRENOM = Sheets("F_Élève").Range("F17").Value
AGE = Sheets("F_Élève").Range("C19").Value
NIVEAU = Sheets("F_Élève").Range("F19").Value
VDATE1 = Sheets("F_Élève").Range("C23").Value
HEURE = Sheets("F_Élève").Range("F23").Value
LIEU = Sheets("F_Élève").Range("C25").Value
SURVEILLANCE = Sheets("F_Élève").Range("F25").Value
ACCIDENT = Sheets("F_Élève").Range("B29").Value
BLESSURE = Sheets("F_Élève").Range("B32").Value
Actions = Sheets("F_Élève").Range("B35").Value
COMMENTAIRES = Sheets("F_Élève").Range("B38").Value
TEMOIN1 = Sheets("F_Élève").Range("C42").Value
VDATET1 = Sheets("F_Élève").Range("C44").Value
TEMOIN2 = Sheets("F_Élève").Range("C46").Value
VDATET2 = Sheets("F_Élève").Range("C48").Value
RESPONSABLE = Sheets("F_Élève").Range("F42").Value
VDATER = Sheets("F_Élève").Range("F44").Value
Direction = Sheets("F_Élève").Range("F46").Value
VDATED = Sheets("F_Élève").Range("F48").Value
MARSH = Sheets("F_Élève").Range("F51").Value
Application.ScreenUpdating = False
'Assing the LastRow variable, but do a quick check for first time user
LastRow = Sheets("D_Base").Range("C" & Rows.Count).End(xlUp).Row + 1
If Sheets("D_Base").Range("C10").Value = "" Then
With Sheets("D_Base")
.Range("C10").Value = ECOLE
.Range("D10").Value = ADRESSE
.Range("E10").Value = VILLE
.Range("F10").Value = TELEPHONE
.Range("G10").Value = NOM
.Range("H10").Value = PRENOM
.Range("I10").Value = AGE
.Range("J10").Value = NIVEAU
.Range("K10").Value = VDATE1
.Range("L10").Value = HEURE
.Range("M10").Value = LIEU
.Range("N10").Value = SURVEILLANCE
.Range("O10").Value = ACCIDENT
.Range("P10").Value = BLESSURE
.Range("Q10").Value = Actions
.Range("R10").Value = COMMENTAIRES
.Range("S10").Value = TEMOIN1
.Range("T10").Value = VDATET1
.Range("U10").Value = TEMOIN2
.Range("V10").Value = VDATET2
.Range("W10").Value = RESPONSABLE
.Range("X10").Value = VDATER
.Range("Y10").Value = Direction
.Range("Z10").Value = VDATED
.Range("AA10").Value = MARSH
End With
Else
With Sheets("D_Base")
.Range("C" & LastRow).Value = ECOLE
.Range("D" & LastRow).Value = ADRESSE
.Range("E" & LastRow).Value = VILLE
.Range("F" & LastRow).Value = TELEPHONE
.Range("G" & LastRow).Value = NOM
.Range("H" & LastRow).Value = PRENOM
.Range("I" & LastRow).Value = AGE
.Range("J" & LastRow).Value = NIVEAU
.Range("K" & LastRow).Value = VDATE1
.Range("L" & LastRow).Value = HEURE
.Range("M" & LastRow).Value = LIEU
.Range("N" & LastRow).Value = SURVEILLANCE
.Range("O" & LastRow).Value = ACCIDENT
.Range("P" & LastRow).Value = BLESSURE
.Range("Q" & LastRow).Value = Actions
.Range("R" & LastRow).Value = COMMENTAIRES
.Range("S" & LastRow).Value = TEMOIN1
.Range("T" & LastRow).Value = VDATET1
.Range("U" & LastRow).Value = TEMOIN2
.Range("V" & LastRow).Value = VDATET2
.Range("W" & LastRow).Value = RESPONSABLE
.Range("X" & LastRow).Value = VDATER
.Range("Y" & LastRow).Value = Direction
.Range("Z" & LastRow).Value = VDATED
.Range("AA" & LastRow).Value = MARSH
End With
End If
'Your message
MsgBox "Les donnŽes ont bien ŽtŽ enregistrŽes.", vbInformation, "Continuer..."
'you can clear the form right here so no need to click two different buttons
'but just ignore and delete the following code if you want.
Sheets("F_Élève").Range("C11,C13,F11,F13,C17,F17,C19,F19,C23,F23,C25,F25,B29,B32,B35,B38,C42,C44,C46,C48,F42,F44,F46,F48,F51").ClearContents 'add all cells or ranges you want
Application.ScreenUpdating = True
End sub