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
| Private Sub btnValider_Click()
Dim L As Integer
Dim tb, i, TxtBox As Object
Dim ErrMsg As String, HasErr As Boolean
'If MsgBox("Confirmez-vous la création de ce nouvel ajout?") = vbYes then No("Demande de confirmation d'ajout") = vbYes Then
ReDim tb(1 To 1, 1 To 11)
'On cherche la prochaine ligne vide de la source
L = Sheets("Feuil2").Range("A" & Rows.Count).End(xlUp).Row + 1
For i = 1 To 11 ' nombres de colonnes
Set TxtBox = Controls("TextBox" & i)
HasErr = TxtBox.Text = ""
ErrMsg = ""
On Error GoTo Eh
Select Case i
Case 1: tb(1, i) = CStr(TxtBox)
Case 2: tb(1, i) = TxtBox
Case 3:
ErrMsg = "Veuillez saisir le N° de l'étape."
tb(1, i) = CInt(TxtBox)
Case 4: tb(1, i) = CStr(TxtBox)
Case 5: ErrMsg = "Veuillez saisir le nombre de km parcourus."
tb(1, i) = CInt(TxtBox)
Case 6: ErrMsg = "Veuillez saisir le Temps de marche."
tb(1, i) = CDate(TxtBox)
Case 7: ErrMsg = "Veuillez saisir le déniveler +."
tb(1, i) = CInt(TxtBox)
Case 8: ErrMsg = "Veuillez saisir le déniveler -."
tb(1, i) = CInt(TxtBox)
Case 9: tb(1, i) = CInt(TxtBox)
Case 10: ErrMsg = "Veuillez saisir L'heure d'arrivée."
tb(1, i) = TxtBox.Value
Case 11: tb(1, i) = CStr(TxtBox)
End Select
If HasErr Then Exit For
Next
Eh:
If (Err.Number <> 0) Or HasErr Then
Err.Clear
TxtBox.SelStart = 0
TxtBox.SelLength = 1000
If ErrMsg = "" Then: ErrMsg = "Valeur incorrecte pour ce champ" ' message d'erreur par défaut
MsgBox ErrMsg, vbExclamation
TxtBox.SetFocus
Exit Sub
End If
Sheets("Feuil2").Range("A" & L).Resize(1, 11) = tb
Feuil3.Range("L9") = Feuil3.Range("L9") + 1
'Réinitialise le contenu des TexteBox
Me.TextBox1 = ""
Me.TextBox2 = ""
Me.TextBox3 = ""
Me.TextBox4 = ""
Me.TextBox5 = ""
Me.TextBox6 = ""
Me.TextBox7 = ""
Me.TextBox8 = ""
Me.TextBox9 = ""
Me.TextBox10 = ""
Me.TextBox11 = ""
'Me.lblMessage = ""
'End If
End Sub |
Partager