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
| Private Sub CmdValider_click()
Dim ID_MaintenancePréventive As Variant, ID_Personnel As Variant, DuréeIntervention As Variant
Dim sql As String, Commentaire As String
Dim DateMaintenancePréventive As Date, DatePrevueInitialement As Date
Dim oRst As DAO.Recordset
Dim odb As DAO.Database
If Me.txtIDDemande.Caption = "null" Then Exit Sub
Set odb = CurrentDb
ID_MaintenancePréventive = Me.txtIDDemande.Caption
If Nz(Me.txtCommentaire, "") = "" Then
Commentaire = ""
Else
Commentaire = Me.txtCommentaire.value
End If
Commentaire = Replace(Commentaire, "'", "''")
DuréeIntervention = Me.listeDurée
sql = "select * from tbl_MaintenancePréventive where id_MaintenancePréventive = " & ID_MaintenancePréventive & ";"
Set oRst = odb.OpenRecordset(sql, dbOpenDynaset)
ID_Périodicité = oRst.Fields("ID_Périodicité").value
DatePrevueInitialement = oRst.Fields("DateProchaineIntervention").value
sql = "Select NombreDeJours from tbl_Périodicité where ID_Periodicité = " & ID_Périodicité & ""
Set oRst = odb.OpenRecordset(sql, dbOpenDynaset)
ProchaineIntervention = oRst.Fields("NombreDeJours").value + Date
sql = "Update tbl_MaintenancePréventive set DateDerniéreIntervention=#" & Date & "#, DateProchaineIntervention = #" & ProchaineIntervention & "# where ID_MaintenancePréventive =" & ID_MaintenancePréventive & ";"
odb.Execute (sql)
sql = "Select Max(ID_HistoriqueMaintenancePréventive) As MaxId from tbl_HistoriqueMaintenancePréventive"
Set oRst = odb.OpenRecordset(sql, dbOpenDynaset)
If oRst.Fields("MaxId").value > 0 Then
MsgBox oRst.Fields("MaxId").value
id_HistoriqueMaintenancePréventive = oRst.Fields("MaxId").value + 1
Else
id_HistoriqueMaintenancePréventive = 1
End If
ID_Personnel = Me.listeIntervenant
sql = "insert into tbl_HistoriqueMaintenancePréventive values (" & id_HistoriqueMaintenancePréventive & ", '" & ID_MaintenancePréventive & "' ," & ID_Personnel & "," & Date & ", " & DatePrevueInitialement & ", '" & Commentaire & "', " & DuréeIntervention & " )"
odb.Execute (sql)
MsgBox ("Votre Intervention a été correctement enregistrée")
DoCmd.Close
Form_SignalerMaintenancePreventiveTerminé.Refresh
End Sub |
Partager