Bonsoir membres du forum,
J'essaie de générer les moyennes des différents niveaux avec 2 procédures;
l'une pour les "MATERNELLE A" "CP1 A" et "CP2 A" (ClaculerMoyenne)
et l'autre pour les "CE1 A" "CE2 A" et "CM1 A" "CM2 A" (ClaculerMoyenneCE2_CM).
Toutes les deux procédures sont appelées ici:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Private Sub cmdCalcul01_Click() On Error Resume Next If LignesInserrees(Me.idCompoF) = False Then MsgBox "Attention !" & vbCrLf & "Aucune note n'a été " & vbCrLf & _ "saisie pour cet élève !", vbExclamation + vbOKOnly, "Pas de Notes" Else If Me.Parent.NiveauEvaluationFr = "Maternelle" Or Me.Parent.NiveauEvaluationFr = _ "CP1 A" Or Me.Parent.NiveauEvaluationFr = "CP2 A" Then ClaculerMoyenne End If If Me.Parent.NiveauEvaluationFr = "CE2 A" Or Me.Parent.NiveauEvaluationFr = _ "CM1 A" Or Me.Parent.NiveauEvaluationFr = "CM1 A" Or Me.Parent.NiveauEvaluationFr = _ "CM2 A" Then ClaculerMoyenneCE2_CM End If DoCmd.RunCommand acCmdRefresh 'MAJ du bilan annuel de l'élève If Me.CompoFRANCAIS = "3" Then 'Pause If BilanDejaGenereFr(Me.ID_Etab, Me.anscol, Me.mle_Eleve, Me.NiveauEvaluationFr) = False Then DoEvents Forms![NOTES DE COMPOSITIONS FR]!BILAN_ANNUEL_FRANCAIS.Form!MoyAnnuel = _ MoyAnnuelleEleveFrancais(Me.anscol, Me.NiveauEvaluationFr, Me.mle_Eleve, Me.ID_Etab) Forms![NOTES DE COMPOSITIONS FR]!BILAN_ANNUEL_FRANCAIS.Form!Classement = "Non généré encore !" Forms![NOTES DE COMPOSITIONS FR]!BILAN_ANNUEL_FRANCAIS.Form!Appreciation = _ AppreciationMoyenne(MoyAnnuelleEleveFrancais(Me.anscol, Me.NiveauEvaluationFr, Me.mle_Eleve, Me.ID_Etab)) If MsgBox("La moyenne annuelle a été calculée, et l'appréciation générée..." & _ vbCrLf & "Il faudra afficher le bilan annuel de la classe pour voir le " _ & "rang général de la classe." & vbCrLf & "Voulez-vous voir son bilan ?", _ vbOKCancel + vbExclamation, "Bilan de l'élève") = vbOK Then Forms![NOTES DE COMPOSITIONS FR]!ctrl_onglet.Pages(2).SetFocus End If Else If MsgBox("La moyenne annuelle a déjà été calculée," & _ vbCrLf & "Il faudra afficher le bilan " & vbCrLf & _ "annuel de la classe pour voir le " _ & "rang général de la classe." & vbCrLf & _ "Voulez-vous voir son bilan ?", _ vbOKCancel + vbExclamation, "Bilan de l'élève") = vbOK Then Forms![NOTES DE COMPOSITIONS FR]!ctrl_onglet.Pages(2).SetFocus End If End If End If Me.NOTES_CLASSES_FRANCAIS_SF.Locked = True cmdCalcul02_Click End If End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub ClaculerMoyenne() On Error Resume Next Dim db As Database Dim rst As Recordset Dim rstNCoef As Recordset Dim rstCoef As Recordset Dim sqlNotesCoef As String Dim sqlCoef As String Dim idX As Long Set db = CurrentDb Dim SQL As String 'Mise à jour du total des notes SQL = "SELECT SUM(NoteFr*coef) AS TotalDesNotes FROM NOTES_CLASSES_FRANCAIS WHERE idCF = " & Me.idCompoF & ";" Set rst = db.OpenRecordset(SQL) If Not rst.EOF Then Me.Total_Notes = rst.Fields("TotalDesNotes") Else Me.Total_Notes = 0 End If 'Mise à jour du total des Coef et de la Moyenne sqlCoef = "SELECT SUM(coef) AS TotalDesCoef FROM NOTES_CLASSES_FRANCAIS WHERE idCF = " & Me.idCompoF & ";" sqlNotesCoef = "SELECT SUM(NoteFr*coef) AS NotesCoef FROM NOTES_CLASSES_FRANCAIS WHERE idCF = " & Me.idCompoF & ";" Set rstCoef = db.OpenRecordset(sqlCoef) Set rstNCoef = db.OpenRecordset(sqlNotesCoef) If Not rstNCoef.EOF And Not rstCoef.EOF Then Me.MoyenneCompo = Round(rstNCoef.Fields("NotesCoef") / rstCoef.Fields("TotalDesCoef"), 2) Else Me.MoyenneCompo = 0 End If 'Mise à jour du total de l'appréciation Me.Appreciation = AppreciationMoyenne(Me.MoyenneCompo) End SubMon objectif est de pouvoir générer les moyennes selon la classe active au clique sur la commande cmdCalcul01_Click
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub ClaculerMoyenneCE2_CM() On Error Resume Next Dim db As Database Dim rst As Recordset Dim rstNCoef As Recordset Dim rstCoef As Recordset Dim sqlNotesCoef As String Dim sqlCoef As String Dim idX As Long Set db = CurrentDb Dim SQL As String '____________________ Dim X As Long Dim Y As Long '____________________ X = 17 Y = 2 '_____________________________ 'Mise à jour du total des notes SQL = "SELECT SUM(NoteFr*coef) AS TotalDesNotes FROM NOTES_CLASSES_FRANCAIS WHERE idCF = " & Me.idCompoF & ";" Set rst = db.OpenRecordset(SQL) If Not rst.EOF Then Me.Total_Notes = rst.Fields("TotalDesNotes") Else Me.Total_Notes = 0 End If 'Mise à jour du total des Coef et de la Moyenne sqlCoef = "SELECT SUM(coef) AS TotalDesCoef FROM NOTES_CLASSES_FRANCAIS WHERE idCF = " & Me.idCompoF & ";" sqlNotesCoef = "SELECT SUM(NoteFr*coef) AS NotesCoef FROM NOTES_CLASSES_FRANCAIS WHERE idCF = " & Me.idCompoF & ";" Set rstCoef = db.OpenRecordset(sqlCoef) Set rstNCoef = db.OpenRecordset(sqlNotesCoef) If Not rstNCoef.EOF And Not rstCoef.EOF Then 'Me.MoyenneCompo = Round(rstNCoef.Fields("NotesCoef") / rstCoef.Fields("TotalDesCoef"), 2) Me.MoyenneCompo = (Round(rstNCoef.Fields("NotesCoef")) / X) * Y Else Me.MoyenneCompo = 0 End If 'Mise à jour du total de l'appréciation If Me.Parent.NiveauEvaluationFr = "Maternelle" Or Me.Parent.NiveauEvaluationFr = _ "CP1 A" Or Me.Parent.NiveauEvaluationFr = "CP2 A" Then Me.Appreciation = AppreciationMoyenne(Me.MoyenneCompo) End If If Me.Parent.NiveauEvaluationFr = "CE2 A" Or Me.Parent.NiveauEvaluationFr = _ "CM1 A" Or Me.Parent.NiveauEvaluationFr = "CM1 A" Or Me.Parent.NiveauEvaluationFr = _ "CM2 A" Then Me.Appreciation = AppreciationMoyenne_2ndaire(Me.MoyenneCompo) End If End Sub
L'erreur constatée est que seule la procédure ClaculerMoyenneCE2_CM marche.
Comment atteindre mon but ?
Cordialement.
Partager