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
| Private Sub UserForm_Initialize()
Dim Fichier As String
Dim x As Long
Dim i As Long
'Chemin et nom du fichier icône à afficher
Fichier = "C:\Users\.ico"
'Vérifie si le fichier existe
If Dir(Fichier) = "" Then Exit Sub
x = ExtractIconA(0, Fichier, 0)
SendMessageA FindWindow(vbNullString, Me.Captde ion), &H80, False, x
'Definit les valeurs par défaut des ComboBox
ComboBox_NbreJours.Value = "0"
ComboBox_Intervention.Value = ""
For i = 1 To 8 '8 = nombre des cellules prises en compte dans le menu déroulant
ComboBox_NbreJours.AddItem Sheets("Listes").Cells(i, 1) '1 = n°colonne, c-a-d colonne A
ComboBox_Intervention.AddItem Sheets("Listes").Cells(i, 2) '1 = n°colonne, c-a-d colonne A
Next
End Sub
'Quand l'utilisateur clic sur le bouton Ok
Private Sub CommandButton_Ok_Click()
Dim i As Integer, Ligne As Long
If ComboBox_NbreJours = "" Then Exit Sub
For i = 1 To ComboBox_NbreJours.Value
'Coloration des Labels en noir
Label_Nmagasin.ForeColor = RGB(0, 0, 0)
Label_Magasin.ForeColor = RGB(0, 0, 0)
Label_NbreCaisses.ForeColor = RGB(0, 0, 0)
Label_NbreJours.ForeColor = RGB(0, 0, 0)
Label_Date.ForeColor = RGB(0, 0, 0)
Label_Intervention.ForeColor = RGB(0, 0, 0)
'Contôles de contenu
If TextBox_Nmagasin.Value = "" Then 'Si rien de saisi dans N° de Magasin
Label_Nmagasin.ForeColor = RGB(255, 0, 0) 'Label N° de Magasin passe en rouge
ElseIf TextBox_Magasin.Value = "" Then
Label_Magasin.ForeColor = RGB(255, 0, 0)
ElseIf TextBox_NbreCaisses.Value = "" Then
Label_NbreCaisses.ForeColor = RGB(255, 0, 0)
ElseIf ComboBox_NbreJours.Value = "" Then
Label_NbreJours.ForeColor = RGB(255, 0, 0)
ElseIf DTPicker_Date.Value = "" Then
Label_Date.ForeColor = RGB(255, 0, 0)
ElseIf ComboBox_Intervention.Value = "" Then
Label_Intervention.ForeColor = RGB(255, 0, 0)
Else
'Si le formulaire est complet, on insère les valeurs dans la feuille
Dim no_ligne As Integer, Retour As String
'no_ligne = N° de ligne de la dernière cellule non vide de la colonne +1
Sheets("Base de Données").Select
no_ligne = Range("A65536").End(xlUp).Row + 1
'Insertion des valeurs sur la feuille
Cells(no_ligne, 1) = TextBox_Nmagasin.Value
Cells(no_ligne, 2) = TextBox_Magasin.Value
Cells(no_ligne, 3) = TextBox_NbreCaisses.Value
Cells(no_ligne, 4) = ComboBox_NbreJours.Value
'
Cells(no_ligne, 6) = ComboBox_Intervention.Value
'
Cells(no_ligne, 9) = DTPicker_Date.Value
'Après insertion, on remet les valeurs initiales
TextBox_Nmagasin.Value = ""
TextBox_Magasin.Value = ""
TextBox_NbreCaisses.Value = ""
ComboBox_NbreJours.Value = ""
ComboBox_Intervention.Value = ""
End If
Next i
ActiveWorkbook.Save
MsgBox "L'enregistrement des données a été réalisé avec succés.", vbInformation + vbOKOnly, "Information"
End Sub |
Partager