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 84 85 86 87 88 89 90 91
| Private Sub appli_Click()
On Error GoTo Err_appli
Dim RS As Recordset, Rech As Recordset, record As Recordset
Dim SQL As String, SQL2 As String
Dim DateC As Date
Dim cycle As Integer
DateC = CDate(DateValue(Me!DateD) - (Weekday(DateValue(Me!DateD), vbMonday) - 1))
DateFin = CDate(Me!DateF)
If DateC < DateFin - nbrSemaine * 7 Then
cycle = ((DateFin - DateC) \ 7 + 1) \ nbrSemaine
Set record = CurrentDb.OpenRecordset("Vacation", dbOpenDynaset)
For n = 1 To cycle
For i = 1 To DCount("No_Equipe", "Equipe")
SQL = "Select * " & _
"FROM [VacationHoraire] " & _
"Where [No_Equipe]=" & i & ""
Set RS = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)
SQL2 = "Select * " & _
"FROM [Technicien] " & _
"Where [No_Equipe]=" & i & "" & _
" Order By No_Equipe ;"
Set Rech = CurrentDb.OpenRecordset(SQL2, dbOpenSnapshot)
If Rech.EOF Then
End If
Rech.MoveFirst
If Not RS.EOF Then
For j = 1 To DCount("Matricule", "Technicien", "No_Equipe = " & i)
RS.MoveFirst
For k = 1 To DCount("Date_vac", "VacationHoraire", "No_Equipe = " & i)
With record
.FindFirst "Date_vac = " & FDateUs(CDate(DateC + RS!Date_vac - 1 + (n - 1) * 7 * nbrSemaine)) & " And Matricule ='" & Rech!Matricule & "'"
If Not (record.NoMatch) Then
.Edit
![NOccupation] = RS!NOccupation
Else
.AddNew
![Date_vac] = CDate(DateC + RS!Date_vac - 1 + (n - 1) * 7 * nbrSemaine)
![Matricule] = Rech!Matricule
![NOccupation] = RS!NOccupation
![NoSemaine] = Format(DateC + RS!Date_vac - 1 + (n - 1) * 7 * nbrSemaine - 1, "ww") - 1
End If
.Update
End With
RS.MoveNext
Next
Rech.MoveNext
Next
End If
Next
Next
RS.Close
Set RS = Nothing
Rech.Close
Set Rech = Nothing
record.Close
Set record = Nothing
DoCmd.Close
Else
MsgBox "Dates incorectes, au minimum un cycle doit être réalisé."
End If
Exit_appli:
Exit Sub
Err_appli:
MsgBox Err.description
Resume Exit_appli
End Sub |
Partager