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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
| Function def_Z2N_test()
'On Error Resume Next
DoCmd.SetWarnings True
Dim rs_der_def As DAO.Recordset
Dim rs_Proprio As DAO.Recordset
Dim temps_ref As Integer, temps_next As Integer
Dim synthèse As String
Dim Commentaire As String
Dim rame As String
Dim Date_Now As Date
Dim Date_Now2 As Date
Dim Date_Griffe As Date
Dim Date_FI As Date
Dim Date_FI2 As String
Dim vehicule1 As String
'Static nom_fichier_Histo As String
'*** RESET GENERAL ***
DoCmd.SetWarnings False
DoCmd.RunSQL "delete * from Test_alerte_Z2N"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_2"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_3"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_4"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_5"
DoCmd.RunSQL "delete * from new_test_Z2N"
DoCmd.RunSQL "delete * from new_test_Z2N_2"
DoCmd.RunSQL "delete * from new_test_Z2N_3"
DoCmd.RunSQL "delete * from new_test_Z2N_4"
DoCmd.RunSQL "delete * from T_Defaut_Comm_Acorel"
DoCmd.RunSQL "delete * from listing_FI"
I = 0
Proprio_4 = ""
Proprio_3 = ""
'----------------------------------------------------------------------------------------------------------------------
date_maj = Forms!analyse!Z2N_date
'dernière_date = Format(DateAdd("d", 1, date_maj), "mm/dd/yyyy")
'Date_Now = Format(Now(), "mm/dd/yy")
'*** SELECTION DE TOUTES LES RAMES QUI ONT COMMUNIQUE SUIVANT LA PERIODE DEFINIE ***
sive2 = "SELECT [Parc Z2N].Rame_Complète, defauts_NAT.Date, [Parc Z2N].Ets_Propriétaire"
sive2 = sive2 & " FROM listing_defauts INNER JOIN (defauts_NAT INNER JOIN [Parc Z2N] ON defauts_NAT.Véhicule = [Parc Z2N].véhicule) ON listing_defauts.Code = defauts_NAT.code_defaut"
sive2 = sive2 & " GROUP BY [Parc Z2N].Rame_Complète, defauts_NAT.Date, listing_defauts.vrai_defaut, [Parc Z2N].Ets_Propriétaire, [Parc Z2N].Série" ', defauts_NAT.exploitation"
sive2 = sive2 & " HAVING (((defauts_NAT.Date)<#" & Format(Now(), "mm/dd/yy") & "# AND (defauts_NAT.Date)>=#" & Format(DateAdd("d", 1, date_maj), "mm/dd/yyyy") & "#) AND ((listing_defauts.vrai_defaut)=True)) AND (([Parc Z2N].Série = ""Z20500"") OR ([Parc Z2N].Série = ""Z5600"") OR ([Parc Z2N].Série = ""Z8800""))" ' AND ((defauts_NAT.exploitation)=True)"
Set rs_sive2 = CurrentDb.OpenRecordset(sive2)
If Not rs_sive2.EOF Then
rs_sive2.MoveLast
a = rs_sive2.RecordCount
If a > 0 Then
rs_sive2.MoveFirst
Do While Not rs_sive2.EOF
DoCmd.RunSQL "insert into test_alerte_Z2N(Rame,[Date Defaut], [Ets Propriétaire]) values('" & rs_sive2("Rame_Complète").Value & "',#" & Format(rs_sive2("Date").Value, "mm/dd/yyyy") & "#,'" & rs_sive2("Ets_Propriétaire").Value & "')"
rs_sive2.MoveNext
Loop
Else
End If
'----------------------------------------------------------------------------------------------------------------------
'*** SELECTION DES RAMES SUIVANT LA REQUETE PRECEDENTE AFIN DE POUVOIR BOUCLER RAME PAR RAME ***
engin = "SELECT test_alerte_Z2N.Rame"
engin = engin & " FROM test_alerte_Z2N"
engin = engin & " GROUP BY test_alerte_Z2N.Rame, test_alerte_Z2N.[Ets Propriétaire]"
engin = engin & " ORDER BY test_alerte_Z2N.[Ets Propriétaire] DESC"
Set rs_engin = CurrentDb.OpenRecordset(engin)
If Not rs_engin.EOF Then
rs_engin.MoveLast
n = rs_engin.RecordCount
Last = (n - 1)
rs_engin.MoveFirst
n2 = rs_engin.AbsolutePosition
Do While Not rs_engin.EOF
'--- Reset pour chaque boucle rame par rame ---
DoCmd.SetWarnings False
nom_fichier = ""
nom_fichier2 = ""
nom_fichier3 = ""
nom_fichier4 = ""
DoCmd.RunSQL "delete * from Test_alerte_Z2N_2"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_3"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_4"
DoCmd.RunSQL "delete * from Test_alerte_Z2N_5"
DoCmd.RunSQL "delete * from new_test_Z2N"
DoCmd.RunSQL "delete * from new_test_Z2N_2"
DoCmd.RunSQL "delete * from new_test_Z2N_3"
DoCmd.RunSQL "delete * from new_test_Z2N_4"
DoCmd.RunSQL "delete * from T_Defaut_Comm_Acorel"
Rame2 = ""
rame = ""
Code2 = ""
Date2 = ""
'----------------------------------------------------------------------------------------------------------------------
'***SELECTION DES DEFAUTS POUR L'ALERTE MAIL***
Rame2 = rs_engin("Rame").Value
'*** Séléction des défauts "en exploitation" et "vrais" et Regroupement par occurences suivant la première apparition (heure la plus tôt) (Boucle Rame par Rame) ***
sive3 = "SELECT Test_Alerte_Z2N.rame, Test_Alerte_Z2N.[Date defaut], Min(defauts_NAT.Première) AS MinDePremière, defauts_NAT.code_defaut, Sum(defauts_NAT.Occurrences) AS SommeDeOccurrences, listing_defauts.Système, listing_defauts.systeme_sollector, defauts_NAT.localisation, listing_defauts.[Criticité SNCF], [Parc Z2N].Ets_Propriétaire"
sive3 = sive3 & " FROM Test_Alerte_Z2N INNER JOIN (listing_defauts INNER JOIN (defauts_NAT INNER JOIN [Parc Z2N] ON defauts_NAT.Véhicule = [Parc Z2N].véhicule) ON listing_defauts.Code = defauts_NAT.code_defaut) ON (Test_Alerte_Z2N.[Date defaut] = defauts_NAT.Date) AND (Test_Alerte_Z2N.Rame = [Parc Z2N].Rame_Complète)"
sive3 = sive3 & " GROUP BY test_alerte_Z2N.rame , Test_Alerte_Z2N.[Date defaut], defauts_NAT.code_defaut, listing_defauts.Système, defauts_NAT.localisation, listing_defauts.[Criticité SNCF], [Parc Z2N].Ets_Propriétaire, defauts_NAT.[série de matériel], listing_defauts.serie, listing_defauts.systeme_sollector, defauts_NAT.exploitation, listing_defauts.vrai_defaut"
sive3 = sive3 & " HAVING ((test_alerte_Z2N.rame like '" & Rame2 & "') AND (listing_defauts.serie = defauts_NAT.[série de matériel]) AND (defauts_NAT.exploitation=True) AND (listing_defauts.vrai_defaut=True))"
Set rs_sive3 = CurrentDb.OpenRecordset(sive3)
If Not rs_sive3.EOF Then
rs_sive3.MoveLast
B = rs_sive3.RecordCount
If B > 0 Then
rs_sive3.MoveFirst
Do While Not rs_sive3.EOF
DoCmd.RunSQL "insert into test_alerte_Z2N_2(Rame,[Date Défaut],[Première heure défaut],[Système Sollector], Système,[Code défaut],Occurrences, Localisation, Criticité,[Ets Propriétaire]) values('" & rs_sive3("Rame").Value & "',#" & Format(rs_sive3("Date defaut").Value, "mm/dd/yyyy") & "#,#" & Format(rs_sive3("MinDePremière").Value, "hh:mm:ss") & "#,'" & rs_sive3("Systeme_sollector").Value & "','" & rs_sive3("Système").Value & "','" & rs_sive3("code_defaut").Value & "'," & rs_sive3("SommeDeOccurrences").Value & ",'" & rs_sive3("localisation").Value & "'," & rs_sive3("Criticité SNCF").Value & ",'" & rs_sive3("Ets_propriétaire").Value & "')"
Equation_CD_Z2N 'Appel au module pour les équations sur les CD Z2N
SQL_Capteur = "SELECT test_alerte_Z2N_2.localisation FROM test_alerte_Z2N_2 WHERE test_alerte_Z2N_2.Rame = '" & Rame2 & "' " ' AND ((Mid(T_SQL_Moy2.localisation, 10,3) = ""SEN"") OR (Mid(T_SQL_Moy2.localisation, 11,3) = ""SEN""))"
Set rs_SQL_Capteur = CurrentDb.OpenRecordset(SQL_Capteur)
If Not rs_SQL_Capteur.EOF Then
rs_SQL_Capteur.MoveLast
countCapt = rs_SQL_Capteur.RecordCount
rs_SQL_Capteur.MoveFirst
Do While Not rs_SQL_Capteur.EOF
LocaCapt = rs_SQL_Capteur("Localisation").Value
LocaCapt1 = Mid(LocaCapt, 10, 3)
LocaCapt2 = Mid(LocaCapt, 11, 3)
If (LocaCapt1 = "SEN" Or LocaCapt2 = "SEN") Then
Capteur = Right(LocaCapt, 5)
Else
End If
rs_SQL_Capteur.MoveNext
Loop
Else
End If
DoCmd.RunSQL "UPDATE Test_alerte_Z2N_2 SET Test_alerte_Z2N_2.Localisation = Mid([Test_alerte_Z2N_2]![Localisation],1,7)" 'Mise à jour du champ localisation pour ne garder que l'info importante (genre DOOR.1 ...)
DoCmd.RunSQL "UPDATE Test_alerte_Z2N_2 INNER JOIN Table_Correspondance_Adressage_Doors_CAVE_Z2N ON Test_alerte_Z2N_2.Localisation = Table_Correspondance_Adressage_Doors_CAVE_Z2N.Door SET Test_alerte_Z2N_2.Localisation = [Table_Correspondance_Adressage_Doors_CAVE_Z2N].[Nom de Porte] WHERE (([Table_Correspondance_Adressage_Doors_CAVE_Z2N].[Door]=[Test_alerte_Z2N_2].[Localisation]))"
rs_sive3.MoveNext
Loop
Else
End If
'----- Selection du vehicule concerné -----
SQL_loca_caisse = "SELECT test_alerte_Z2N_2.localisation FROM test_alerte_Z2N_2"
Set rs_loca_caisse = CurrentDb.OpenRecordset(SQL_loca_caisse)
If Not rs_loca_caisse.EOF Then
rs_loca_caisse.MoveFirst
loca = rs_loca_caisse("localisation")
If loca = "GPS" Or loca = "Modem" Or loca = "BM1ZI" Or loca = "BM2ZI" Then
vehicule1 = "Zimpaire"
SQL_loca_caisse2 = "SELECT [Parc Z2N].num_caisse FROM [Parc Z2N] WHERE [Parc Z2N].[Type Caisse] = '" & vehicule1 & "' "
Set rs_sql_loca_caisse2 = CurrentDb.OpenRecordset(SQL_loca_caisse2)
rs_sql_loca_caisse2.MoveFirst
vehicule = rs_sql_loca_caisse2("num_caisse").Value
ElseIf loca = "CCEU" Or loca = "BM1ZP" Or loca = "BM2ZP" Or loca = "UCD" Then
vehicule1 = "Zpaire"
SQL_loca_caisse3 = "SELECT [Parc Z2N].num_caisse FROM [Parc Z2N] WHERE [Parc Z2N].[Type Caisse] = '" & vehicule1 & "' "
Set rs_sql_loca_caisse3 = CurrentDb.OpenRecordset(SQL_loca_caisse3)
rs_sql_loca_caisse3.MoveFirst
vehicule = rs_sql_loca_caisse3("num_caisse").Value
Else
SQL_caisse1 = "SELECT Table_Correspondance_Adressage_Doors_CAVE_Z2N.vehicule FROM test_alerte_Z2N_2 INNER JOIN Table_Correspondance_Adressage_Doors_CAVE_Z2N ON Table_Correspondance_Adressage_Doors_CAVE_Z2N.[Nom de Porte] = test_alerte_Z2N_2.localisation WHERE test_alerte_Z2N_2.localisation = '" & loca & "' "
Set rs_SQL_caisse1 = CurrentDb.OpenRecordset(SQL_caisse1)
rs_SQL_caisse1.MoveFirst
vehicule = rs_SQL_caisse1("vehicule").Value
End If
Else
End If
'--- Ajout des données dans la table qui servira pour la création de l'état pour l'alerte mail ---
SQL_New_Test_Z2N = "INSERT INTO new_test_Z2N ( Rame, [Date défaut], [Code Défaut], [Système Sollector], Système, Occurences, [Ets Propriétaire], Criticité, [Première heure défaut] )"
SQL_New_Test_Z2N = SQL_New_Test_Z2N & " SELECT Test_alerte_Z2N_2.Rame, Test_alerte_Z2N_2.[Date défaut], Test_alerte_Z2N_2.[Code Défaut], Test_Alerte_Z2N_2.[Système Sollector], Test_alerte_Z2N_2.Système, Sum(Test_alerte_Z2N_2.Occurrences) AS SommeDeOccurrences, Test_alerte_Z2N_2.[Ets Propriétaire], Test_alerte_Z2N_2.Criticité, First(Test_alerte_Z2N_2.[Première heure défaut]) AS [PremierDePremière heure défaut]"
SQL_New_Test_Z2N = SQL_New_Test_Z2N & " FROM Test_alerte_Z2N_2"
SQL_New_Test_Z2N = SQL_New_Test_Z2N & " GROUP BY Test_alerte_Z2N_2.Rame, Test_alerte_Z2N_2.[Date défaut], Test_alerte_Z2N_2.[Code Défaut], Test_Alerte_Z2N_2.[Système Sollector], Test_alerte_Z2N_2.Système, Test_alerte_Z2N_2.[Ets Propriétaire], Test_alerte_Z2N_2.Criticité"
SQL_New_Test_Z2N = SQL_New_Test_Z2N & " ORDER BY Test_alerte_Z2N_2.[Ets Propriétaire] DESC"
DoCmd.RunSQL (SQL_New_Test_Z2N)
DoCmd.RunSQL "UPDATE new_test_Z2N INNER JOIN listing_defauts ON new_test_Z2N.[Code Défaut] = listing_defauts.Code SET new_test_Z2N.Description = [listing_defauts].[Intitulé], new_test_Z2N.Préconisations = [listing_defauts].[preconisation]"
Else
End If
'----------------------------------------------------------------------------------------------------------------------
'*** Selection du code défaut et de la date pour des boucles code par code et date par date ***
SQL_Code = "SELECT new_test_Z2N.[code défaut], new_test_Z2N.[Date Défaut]"
SQL_Code = SQL_Code & " FROM new_test_Z2N"
SQL_Code = SQL_Code & " GROUP BY new_test_Z2N.[code défaut], new_test_Z2N.[Date défaut]"
Set rs_SQL_Code = CurrentDb.OpenRecordset(SQL_Code)
If Not rs_SQL_Code.EOF Then
rs_SQL_Code.MoveLast
c = rs_SQL_Code.RecordCount
If c > 0 Then
rs_SQL_Code.MoveFirst
Do While Not rs_SQL_Code.EOF
Date2 = Format(rs_SQL_Code("Date défaut").Value, "dd/mm/yyyy")
Code2 = rs_SQL_Code("Code défaut").Value
'--- Ré-écriture de la localisation du code défaut selon le nombre d'occurences et la localisation initiale pour rassembler diverses occurences similaires (ex: DOOR.1, DOOR.2,DOOR.13 ...) dans une seule case ---
SQL_Localisation = "SELECT Test_alerte_Z2N_2.Occurrences, Test_alerte_Z2N_2.Localisation, Test_alerte_Z2N_2.[Code Défaut], Test_alerte_Z2N_2.[Date Défaut]"
SQL_Localisation = SQL_Localisation & " FROM Test_alerte_Z2N_2"
SQL_Localisation = SQL_Localisation & " GROUP BY Test_alerte_Z2N_2.Localisation, Test_alerte_Z2N_2.[Code Défaut], Test_alerte_Z2N_2.Occurrences, Test_alerte_Z2N_2.[Date Défaut]"
SQL_Localisation = SQL_Localisation & " HAVING ('" & Code2 & "' = Test_alerte_Z2N_2.[Code Défaut]) AND (#" & Format(Date2, "mm/dd/yyyy") & "# = Test_alerte_Z2N_2.[Date Défaut])"
Set rs_SQL_Localisation = CurrentDb.OpenRecordset(SQL_Localisation)
If Not rs_SQL_Localisation.EOF Then
rs_SQL_Localisation.MoveLast
d = rs_SQL_Localisation.RecordCount
If d > 0 Then
rs_SQL_Localisation.MoveFirst
Do While Not rs_SQL_Localisation.EOF
DoCmd.RunSQL "INSERT INTO new_test_Z2N_2 (SommeDeOccurrences, Localisation, [Code Défaut], [Date Défaut]) values (" & rs_SQL_Localisation("Occurrences").Value & ", '" & rs_SQL_Localisation("Localisation").Value & "', '" & rs_SQL_Localisation("Code Défaut").Value & "', #" & Format(rs_SQL_Localisation("Date Défaut").Value, "dd/mm/yyyy") & "#)"
rs_SQL_Localisation.MoveNext
Loop
Else
End If
'--- Mise à jour du champ localisation adoptant le format de l'information voulue dans la table qui servira à l'état de l'alerte mail ---
If Code2 = "AC-302" Then
DoCmd.RunSQL "UPDATE new_test_Z2N_2 SET new_test_Z2N_2.Localisation = [new_test_Z2N_2].[SommeDeOccurrences] & "" Occurrence(s) sur "" & [new_test_Z2N_2].[localisation] & "" "" & '" & Capteur & "' & Chr(13) & Chr(10) WHERE (([new_test_Z2N_2].[Code Défaut]= '" & Code2 & "') AND (new_test_Z2N_2.[date Défaut] = #" & Format(Date2, "dd/mm/yyyy") & "# ))"
Else: DoCmd.RunSQL "UPDATE new_test_Z2N_2 SET new_test_Z2N_2.Localisation = [new_test_Z2N_2].[SommeDeOccurrences] & "" Occurrence(s) sur "" & [new_test_Z2N_2].[localisation] & Chr(13) & Chr(10) WHERE (([new_test_Z2N_2].[Code Défaut]= '" & Code2 & "') AND (new_test_Z2N_2.[date Défaut] = #" & Format(Date2, "dd/mm/yyyy") & "# ))"
End If
'----------------------------------------------------------------------------------------------------------------------
Else
End If
'----------------------------------------------------------------------------------------------------------------------
'--- Ré-écriture de la localisation du code défaut selon le nombre d'occurences et la localisation initiale pour rassembler diverses occurences similaires (ex: DOOR.1, DOOR.2,DOOR.13 ...) dans une seule case ---
SQL_synthèse = "SELECT new_test_Z2N_2.Localisation"
SQL_synthèse = SQL_synthèse & " FROM new_test_Z2N_2"
SQL_synthèse = SQL_synthèse & " WHERE (new_test_Z2N_2.[code défaut] = '" & Code2 & "') AND ([new_test_Z2N_2].[Date Défaut]= #" & Format(Date2, "dd/mm/yyyy") & "#)"
Set rs_SQL_synthèse = CurrentDb.OpenRecordset(SQL_synthèse)
If Not rs_SQL_synthèse.EOF Then
rs_SQL_synthèse.MoveLast
e = rs_SQL_synthèse.RecordCount
rs_SQL_synthèse.MoveFirst
Do While Not rs_SQL_synthèse.EOF
synthèse = synthèse & rs_SQL_synthèse("Localisation").Value
rs_SQL_synthèse.MoveNext
Loop
'--- Mise à jour du champ localisation avec l'information finale dans la table qui servira à l'état de l'alerte mail ---
DoCmd.RunSQL "UPDATE new_test_Z2N SET new_test_Z2N.Localisation = '" & synthèse & "' WHERE ((new_test_Z2N.[Code Défaut] = '" & Code2 & "') AND ([new_test_Z2N].[Date Défaut]= #" & Format(Date2, "mm/dd/yyyy") & "#))"
synthèse = ""
DoCmd.RunSQL "delete * from new_test_Z2N_2"
'----------------------------------------------------------------------------------------------------------------------
Else
End If
'----------------------------------------------------------------------------------------------------------------------
rs_SQL_Code.MoveNext
Loop 'Boucle Code par Code
Else
End If
Else
End If
'----------------------------------------------------------------------------------------------------------------------
'*** INSERTION DES DEFAUTS BM RECUEILLIS DANS LE PROGRAMME DE CHRISTOPHE PAQUIER DANS LA TABLE SERVANT A L'ALERTE MAIL***
'DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[Système Sollector] = ""Traction"" AND new_test_Z2N.rame = '" & Rame2 & "' "
DoCmd.RunSQL "INSERT INTO new_test_Z2N ( Rame, [Code Défaut], [Date Défaut], [Première Heure Défaut], localisation, Description, [Temps depuis dernier Reset], Préconisations ) SELECT alerte_Z2N.Engin, alerte_Z2N.Code_defaut, alerte_Z2N.Date_defaut, alerte_Z2N.Heure_defaut, alerte_Z2N.localisation, alerte_Z2N.defaut, alerte_Z2N.temps_defaut, alerte_Z2N.preconisation FROM alerte_Z2N WHERE (((alerte_Z2N.Engin)='" & Rame2 & "'))"
DoCmd.RunSQL "INSERT INTO new_test_Z2N ( Rame, [Code Défaut], [Date Défaut], [Première Heure Défaut], localisation, Description, [Temps depuis dernier Reset], Préconisations ) SELECT alerte_Z2N_2.Engin, alerte_Z2N_2.Code_defaut, alerte_Z2N_2.Date_defaut, alerte_Z2N_2.Heure_defaut, alerte_Z2N_2.localisation, alerte_Z2N_2.defaut, alerte_Z2N_2.temps_defaut, alerte_Z2N_2.preconisation FROM alerte_Z2N_2 WHERE (((alerte_Z2N_2.Engin)='" & Rame2 & "'))"
DoCmd.RunSQL "UPDATE [Parc Z2N] INNER JOIN (listing_defauts INNER JOIN new_test_Z2N ON listing_defauts.Code = new_test_Z2N.[Code Défaut]) ON ([Parc Z2N].Série = listing_defauts.serie) AND ([Parc Z2N].Rame_Complète = new_test_Z2N.Rame) SET new_test_Z2N.[Système Sollector] = listing_defauts.systeme_sollector, new_test_Z2N.système = listing_defauts.système, new_test_Z2N.criticité = listing_defauts.[criticité SNCF] WHERE ([Parc Z2N].série = ""Z20500"" AND new_test_Z2N.criticité is null AND new_test_Z2N.système is null AND new_test_Z2N.[Système Sollector] is null)"
DoCmd.RunSQL "UPDATE new_test_Z2N INNER JOIN [Parc Z2N] ON new_test_Z2N.rame = [parc Z2N].rame_complète SET new_test_Z2N.[Ets propriétaire] = [Parc Z2N].ets_propriétaire WHERE new_test_Z2N.[ETS Propriétaire] is null "
DoCmd.RunSQL "UPDATE new_test_Z2N INNER JOIN defauts_NAT ON new_test_Z2N.exploitation = defauts_NAT.exploitation SET new_test_Z2N.exploitation = defauts_NAT.exploitation"
DoCmd.RunSQL "UPDATE new_test_Z2N SET new_test_Z2N.[Temps depuis dernier reset] = ""Temps depuis dernier reset du BM: "" & chr(13) & new_test_Z2N.[temps depuis dernier reset] WHERE new_test_Z2N.[temps depuis dernier reset] is not null"
'--- Requêtes pour la suppression des CD liés au système Traction issus de la sélection de Benjamin MIRLINK pour ne garder que ceux de la séléction de Christophe PAQUIER ---
SQL_Delete = "SELECT new_test_Z2N.[code défaut] FROM new_test_Z2N GROUP BY new_test_Z2N.[code défaut]"
Set rs_sql_delete = CurrentDb.OpenRecordset(SQL_Delete)
If Not rs_sql_delete.EOF Then
rs_sql_delete.MoveLast
o = rs_sql_delete.RecordCount
rs_sql_delete.MoveFirst
Do While Not rs_sql_delete.EOF
code_delete = rs_sql_delete("code défaut").Value
SQL_Delete2 = "SELECT new_test_Z2N.[Temps depuis dernier reset], new_test_Z2N.description FROM new_test_Z2N INNER JOIN alerte_Z2N_2 ON new_test_Z2N.rame = alerte_Z2N_2.engin WHERE new_test_Z2N.[code défaut] = '" & code_delete & "' AND new_test_Z2N.description <> alerte_Z2N_2.defaut "
Set rs_sql_delete2 = CurrentDb.OpenRecordset(SQL_Delete2)
If Not rs_sql_delete2.EOF Then
rs_sql_delete2.MoveLast
p = rs_sql_delete2.RecordCount
If p > 1 Then
DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[code défaut] = '" & code_delete & "' and new_test_Z2N.[Temps depuis dernier reset] is null "
Else
End If
Else
End If
rs_sql_delete.MoveNext
Loop
Else
End If
'*** DEFAUT COMMUNICATION Z2N SYSTEME ACOREL CD AC-121 non présent (Echec de l'envoi normal du fichier CAVE) ***
def_comm_CAVE_Acorel
'********
'*** Equation sur le défaut de communication BM CD 22-02-00 ***
SQL_comm_BM = "SELECT new_test_Z2N.occurences FROM new_test_Z2N WHERE new_test_Z2N.[code défaut] = ""22-02-00"" "
Set rs_SQL_comm_BM = CurrentDb.OpenRecordset(SQL_comm_BM)
If Not rs_SQL_comm_BM.EOF Then
Ct_Occurences = rs_SQL_comm_BM("Occurences").Value
If Ct_Occurences >= 5 Then 'Nombre à définir convenablement
DoCmd.RunSQL "UPDATE new_test_Z2N SET new_test_Z2N.Description = new_test_Z2N.description & "" "" & ""Défaut de communication: Plus de 5 occurences du code défaut 22-02-00"" WHERE new_test_Z2N.[code défaut] = ""22-02-00"" AND new_test_Z2N.Occurences >= 5 "
Else: DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[Code Défaut] = ""22-02-00"" AND new_test_Z2N.occurences < 5 "
End If
Else
End If
'********
'*** Equation sur le défaut de communication GPS CD AC-150 ***
SQL_comm_GPS = "SELECT new_test_Z2N.occurences FROM new_test_Z2N WHERE new_test_Z2N.[code défaut] = ""AC-150"" "
Set rs_SQL_comm_GPS = CurrentDb.OpenRecordset(SQL_comm_GPS)
If Not rs_SQL_comm_GPS.EOF Then
Ct_Occurences2 = rs_SQL_comm_GPS("Occurences").Value
If Ct_Occurences2 >= 5 Then 'Nombre à définir convenablement
DoCmd.RunSQL "UPDATE new_test_Z2N SET new_test_Z2N.Description = new_test_Z2N.description & "" "" & ""Défaut de communication: Plus de 5 occurences du code défaut AC-150"" WHERE new_test_Z2N.[code défaut] = ""AC-150"" "
Else: DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[Code Défaut] = ""AC-150"" AND new_test_Z2N.occurences < 5 "
End If
Else
End If
'********
'*** Equation sur le défaut de communication GPRS CD AC-151 ***
SQL_comm_GPRS = "SELECT new_test_Z2N.occurences FROM new_test_Z2N WHERE new_test_Z2N.[code défaut] = ""AC-151"" "
Set rs_SQL_comm_GPRS = CurrentDb.OpenRecordset(SQL_comm_GPRS)
If Not rs_SQL_comm_GPRS.EOF Then
Ct_Occurences3 = rs_SQL_comm_GPRS("Occurences").Value
If Ct_Occurences3 >= 5 Then 'Nombre à définir convenablement
DoCmd.RunSQL "UPDATE new_test_Z2N SET new_test_Z2N.Description = new_test_Z2N.description & "" "" & ""Défaut de communication: Plus de 5 occurences du code défaut AC-151"" WHERE new_test_Z2N.[code défaut] = ""AC-151"" "
Else: DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[Code Défaut] = ""AC-151"" AND new_test_Z2N.occurences < 5 "
End If
Else
End If
'********
DoCmd.RunSQL "UPDATE new_test_Z2N INNER JOIN ([Parc Z2N] INNER JOIN defauts_nat ON [Parc Z2N].véhicule = defauts_NAT.véhicule) ON new_test_Z2N.rame = [Parc Z2N].rame_complète SET new_test_Z2N.exploitation = defauts_NAT.exploitation WHERE defauts_NAT.code_defaut = new_test_Z2N.[code défaut] AND defauts_NAT.première = new_test_Z2N.[Première heure défaut] AND new_test_Z2N.Rame = [Parc Z2N].rame_complète AND defauts_NAT.[Date] = new_test_Z2N.[Date Défaut]"
DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[code défaut] = ""AC-102"" "
DoCmd.RunSQL "DELETE FROM new_test_Z2N WHERE new_test_Z2N.[code défaut] = ""AC-117"" "
'*** REX des alertes dans une table ordonnancées par rame et par date ***
SQL_REX = "INSERT INTO REX_Alerte_CD ( Rame, [Date Défaut], [Première Heure Défaut], [Système Sollector], Système, [Code Défaut], Occurences, Localisation, Criticité, [ETS Propriétaire], Description, Préconisations, Exploitation, [Temps depuis dernier Reset] )"
SQL_REX = SQL_REX & " SELECT new_test_Z2N.Rame, new_test_Z2N.[Date Défaut], new_test_Z2N.[Première Heure Défaut], new_test_Z2N.[Système Sollector], new_test_Z2N.Système, new_test_Z2N.[Code Défaut], new_test_Z2N.Occurences, new_test_Z2N.Localisation, new_test_Z2N.Criticité, new_test_Z2N.[ETS Propriétaire], new_test_Z2N.Description, new_test_Z2N.Préconisations, new_test_Z2N.Exploitation, new_test_Z2N.[Temps depuis dernier Reset]"
SQL_REX = SQL_REX & " FROM new_test_Z2N"
SQL_REX = SQL_REX & " GROUP BY new_test_Z2N.Rame, new_test_Z2N.[Date Défaut], new_test_Z2N.[Première Heure Défaut], new_test_Z2N.[Système Sollector], new_test_Z2N.Système, new_test_Z2N.[Code Défaut], new_test_Z2N.Occurences, new_test_Z2N.Localisation, new_test_Z2N.Criticité, new_test_Z2N.[ETS Propriétaire], new_test_Z2N.Description, new_test_Z2N.Préconisations, new_test_Z2N.Exploitation, new_test_Z2N.[Temps depuis dernier Reset]"
SQL_REX = SQL_REX & " ORDER BY new_test_Z2N.[Code défaut], new_test_Z2N.[Date Défaut] DESC, new_test_Z2N.Rame"
DoCmd.RunSQL (SQL_REX)
'*********************
'--- Selection de l'Ets propriétaire pour l'adressage des mails ---
sive4 = "SELECT new_test_Z2N.[ETS Propriétaire]"
sive4 = sive4 & " FROM new_test_Z2N"
Set rs_sive4 = CurrentDb.OpenRecordset(sive4)
If Not rs_sive4.EOF Then
rs_sive4.MoveLast
f = rs_sive4.RecordCount
rs_sive4.MoveFirst
Proprio = rs_sive4("ETS Propriétaire").Value
ElseIf n2 = Last Then
LastSend = 1
GoTo envoi_mail_Z2N
Else
End If
'*** Création PDF + Mail ***
If Not rs_sive4.EOF Then
nom_fichier3 = Rame2 & "_" & "Codes_Défauts" & "_" & " alerte Z2N du " & Day(Now()) & "_" & Month(Now()) & "_" & Year(Now())
SaveAsPDF "test_alerte_Z2N", , nom_fichier3, "D:\Z2N\Alertes Défauts"
envoi_mail_Z2N:
mail_Z2N_test 'Appel au sous programme concernant la création et l'envoi des mails
Proprio_3 = Proprio
Else
End If
'*** Vers Listing_FI ***
Module_FI
'********
rs_engin.MoveNext
n2 = n2 + 1
Loop 'Boucle Rame par Rame
Else
End If
Proprio_3 = ""
nom_fichier3 = ""
nom_fichier_Histo = ""
nom_fichier = ""
def_comm_CAVE_Acorel2 'Bouclage pour vérifier la communication CAVE des rames n'ayant pas communiqué de défauts dans la période définie (Donc non présents dans la boucle rame par rame initiale)
nom_fichier4 = ""
MAJ_Listing_FI 'Mise à jour de la table Listing_FI pour le champ localisation avec regroupement.
DoCmd.RunSQL "UPDATE REX_Alerte_CD INNER JOIN [Parc Z2N] ON [Parc Z2N].Rame_complète = REX_Alerte_CD.Rame SET REX_Alerte_CD.[Série Matériel] = [Parc Z2N].Série WHERE REX_Alerte_CD.Rame = [Parc Z2N].rame_complète"
Else
End If
DoCmd.SetWarnings True
End Function |
Partager