Private Sub TextCode_Change()
Dim Ctrl As Control
Dim Ctrl2 As Control
Dim Trouvé As Boolean
Me.TextCode.Text = UCase(Me.TextCode)
If Not EnableEvents Then Exit Sub
'on cherche le nom associé au code dans la TS "t_Noms"
With Sheets("Liste agents").ListObjects("t_Noms")
Set Trouve = .ListColumns(1).Range.Find(Me.TextCode, lookat:=xlWhole)
If Not Trouve Is Nothing Then
Me.T_bx_Noms = Trouve.Offset(0, 1)
Else
Me.T_bx_Noms = ""
End If
End With
'on cherche dans la TS t_Saisie la ligne qui correspond au code ET à la date du jour
With Sheets("Saisie").ListObjects("t_Saisie")
Trouvé = False
For I = 1 To .ListRows.Count
If .ListColumns("Code agent").DataBodyRange(I) = Me.TextCode And .ListColumns("Date").DataBodyRange(I) = Me.T_bx_DateJour Then
lig = I
Trouvé = True
Exit For
End If
Next I
If Not Trouvé Then Exit Sub 'pas de ligne correspondante ==> l'employé n'a jamais rien saisi pour cette journée
'on charge les horaires déjà saisies pour la date du jour
Me.T_bx_Noms = .DataBodyRange(I, 2)
Me.Tbx_DebMat.Value = Format(.DataBodyRange(I, 4), "hh:mm")
Me.Tbx_FinMat.Value = Format(.DataBodyRange(I, 5), "hh:mm")
Me.Tbx_DebAPM.Value = Format(.DataBodyRange(I, 6), "hh:mm")
Me.Tbx_FinAPM.Value = Format(.DataBodyRange(I, 7), "hh:mm")
Me.Tbx_DebSoir.Value = Format(.DataBodyRange(I, 8), "hh:mm")
Me.Tbx_FinSoir.Value = Format(.DataBodyRange(I, 9), "hh:mm")
Me.T_bx_Commentaire = .DataBodyRange(I, 11)
'on rend tous les checkbox disable et invisible
For Each Ctrl In Me.Frame2.Controls
If TypeName(Ctrl) = "TextBox" Then
If Left(Ctrl.Name, 4) = "Tbx_" Then
Nom = Replace(Ctrl.Name, "Tbx_", "")
Ctrl.Enabled = False ' (Ctrl.Value = "")
Me.Frame2.Controls("Chk_" & Nom).Enabled = False '(Ctrl.Value = "")
Me.Frame2.Controls("Chk_" & Nom).Visible = False '(Ctrl.Value = "")
End If
End If
Next Ctrl
End With
Select Case LastPointé
Case "Tbx_FinSoir"
'tout est pointé==> on garde tout masqué et disable
Case "Tbx_DebSoir"
Me.Tbx_FinSoir.Enabled = True
Me.Chk_FinSoir.Enabled = True
Me.Chk_FinSoir.Visible = True
Case "Tbx_FinAPM"
Me.Tbx_FinSoir.Enabled = True
Me.Tbx_DebSoir.Enabled = True
Me.Chk_FinSoir.Enabled = True
Me.Chk_DebSoir.Enabled = True
Me.Chk_FinSoir.Visible = True
Me.Chk_DebSoir.Visible = True
Case "Tbx_DebAPM"
Me.Tbx_FinSoir.Enabled = True
Me.Tbx_DebSoir.Enabled = True
Me.Tbx_FinAPM.Enabled = True
Me.Chk_FinSoir.Enabled = True
Me.Chk_DebSoir.Enabled = True
Me.ChK_FinAPM.Enabled = True
Me.Chk_FinSoir.Visible = True
Me.Chk_DebSoir.Visible = True
Me.ChK_FinAPM.Visible = True
Case "Tbx_FinMat"
Me.Tbx_FinSoir.Enabled = True
Me.Tbx_DebSoir.Enabled = True
Me.Tbx_FinAPM.Enabled = True
Me.Tbx_DebAPM.Enabled = True
Me.Chk_FinSoir.Enabled = True
Me.Chk_DebSoir.Enabled = True
Me.ChK_FinAPM.Enabled = True
Me.Chk_DebAPM.Enabled = True
Me.Chk_FinSoir.Visible = True
Me.Chk_DebSoir.Visible = True
Me.ChK_FinAPM.Visible = True
Me.Chk_DebAPM.Visible = True
Case "Tbx_DebMat"
Me.Tbx_FinSoir.Enabled = True
Me.Tbx_DebSoir.Enabled = True
Me.Tbx_FinAPM.Enabled = True
Me.Tbx_DebAPM.Enabled = True
Me.Tbx_FinMat.Enabled = True
Me.Chk_FinSoir.Enabled = True
Me.Chk_DebSoir.Enabled = True
Me.ChK_FinAPM.Enabled = True
Me.Chk_DebAPM.Enabled = True
Me.Chk_FinMat.Enabled = True
Me.Chk_FinSoir.Visible = True
Me.Chk_DebSoir.Visible = True
Me.ChK_FinAPM.Visible = True
Me.Chk_DebAPM.Visible = True
Me.Chk_FinMat.Visible = True
Case Else
Me.Tbx_FinSoir.Enabled = True
Me.Tbx_DebSoir.Enabled = True
Me.Tbx_FinAPM.Enabled = True
Me.Tbx_DebAPM.Enabled = True
Me.Tbx_FinMat.Enabled = True
Me.Tbx_DebMat.Enabled = True
Me.Chk_FinSoir.Enabled = True
Me.Chk_DebSoir.Enabled = True
Me.ChK_FinAPM.Enabled = True
Me.Chk_DebAPM.Enabled = True
Me.Chk_FinMat.Enabled = True
Me.Chk_DebMat.Enabled = True
Me.Chk_FinSoir.Visible = True
Me.Chk_DebSoir.Visible = True
Me.ChK_FinAPM.Visible = True
Me.Chk_DebAPM.Visible = True
Me.Chk_FinMat.Visible = True
Me.Chk_DebMat.Visible = True
End Select
CalculerTotalJournée
End Sub