Bonjour membres du forum,
Pourriez-vous m'indiquer à quelle ligne dois-je placer une procédure dans le code suivant afin d'éviter des doublons ?
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
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 Private Sub BtnEnregisterElevesComposants_Click() Dim stMsg As String Dim Itm As Variant Dim oDb As Database Dim oRS As Recordset Dim critere As String Dim eleve As String Dim ajouter As Boolean On Error GoTo OUMAR With Me.ListeELEVES_ANNEE_CLASSE '' contrôle saisie élèves If .ItemsSelected.Count = 0 Then Exit Sub 'contrôle saisie Classe If IsNull(Me.lstClasse_Evaluation) Then MsgBox "Sélectionnez une classe.", vbCritical Me.lstClasse_Evaluation.SetFocus 'Me.lstClasse_Evaluation.Dropdown **** Pour dérouler le combobox à l'aide de la méthode DROPDOWN SendKeys "{F4}" '*** Pour dérouler le combobox à l'aide de l'envoi de touche clavier (F4) Exit Sub End If Set oDb = CurrentDb Set oRS = oDb.OpenRecordset("Tbl_EVALUATION_NIVEAU_SCOLAIRE", dbOpenDynaset) For Each Itm In .ItemsSelected eleve = .Column(4, Itm) 'oRS.FindFirst "[Nom_Prenoms_EleveComposant] LIKE '*" & Eleve & "*'" ''Cette ligne de code modifiée à cause des mots contenant l'apostrophe oRS.FindFirst "[Nom_Prenoms_EleveComposant] LIKE ""*" & eleve & "*""" ajouter = False If oRS.NoMatch Then ajouter = True 'Add the record to the table and stMsg = "L'élève " & eleve & " a été rajouté à la liste, avec succès !" Else Dim fld As Field stMsg = "L'élève " & eleve & " existe déjà dans la table !" & vbLf '********************** stMsg = stMsg & "avec les données suivantes :" & vbCrLf For Each fld In oRS.Fields stMsg = stMsg & fld.Name & " : " & fld.Value & vbCrLf Next fld stMsg = "Année scolaire en cours : " & Me.lstAnnee_Evaluation & vbCrLf & vbCrLf & stMsg & vbCrLf & "Voulez-vous le rajouter ?" If MsgBox(stMsg, vbQuestion + vbYesNo, "Ajouter un Elève") = vbNo Then ajouter = False Else ajouter = True 'Add the record to the table End If End If 'stMsg = stMsg & .Column(4, Itm) & vbCrLf If ajouter = True Then With oRS .AddNew ![NumEnregistreComposant] = f_NumAutoEnregistrementElevesComposants() + 1 ![Nom_Prenoms_EleveComposant] = Me.ListeELEVES_ANNEE_CLASSE.Column(4, Itm) '![COMPOSITION] = Me.ListeComposition_Evaluation ![NiveauCompositionFrancais] = Me.ListeNiveauEVALUATION ![IdEcole] = Me.ID_ETABL_FREQ ![AnneeScol] = Me.ANNEE_SCOL ![NumInsCreleve] = Me.ListeELEVES_ANNEE_CLASSE.Column(2, Itm) ![Mleeleve] = Me.ListeELEVES_ANNEE_CLASSE.Column(3, Itm) .Update End With MsgBox "Année scolaire en cours : " & Me.lstAnnee_Evaluation & vbCrLf & stMsg, vbInformation + vbOKOnly, "Elève ajouté" End If Next Itm ' enlever la sélection .RowSource = .RowSource ' affichage des éléments saisis Me.Refresh Me.ListeELEVES_ANNEE_CLASSE.Requery Forms("Frm_EvaluationScolaireElevesECIND").Tbl_EVALUATION_NIVEAU_SCOLAIRE_SFrm.Requery ListeELEVES_ANNEE_CLASSE.RowSource = ListeELEVES_ANNEE_CLASSE.RowSource End With Forms!Frm_EvaluationScolaireElevesECIND!CtlTabEVALUATION_COMPOSITION.Pages(1).SetFocus DoCmd.GoToRecord , , acLast OUMAR_Exit: Exit Sub OUMAR: MsgBox err.Description, vbExclamation + vbOKOnly, err.Number Resume OUMAR_Exit 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 ''FONCTION POUR CONTROLER LES DOUBLONS DE L'ENREGISTREMENT DES ELEVES ''COMPOSANTS PAR COMPOSITION, Niveau de Composition ET ANNEE SCOLAIRE, ECOLE Public Function fEstEleveDejaComposant(ETABL As Long, NumInsc As Long, Mleelv As Long, Ansco As String, Composi As Long, NivCompo As String) As Boolean On Error GoTo MOROBABOUMAR Dim nbElement As Long nbElement = DCount("*", "Req_Tbl_EVALUATION_NIVEAU_SCOLAIRE", "IdEcole = " & ETABL & "and NumInsCreleve =" & NumInsc & "and MleEleve =" & Mleelv & "and AnneeScol ='" & Ansco & "'and COMPOSITION =" & Composi & "and NiveauCompositionFrancais ='" & NivCompo & "'") fEstEleveDejaComposant = (nbElement <> 0) Exit Function MOROBABOUMAR: MsgBox "Erreur n° " & err.Number & vbCrLf & err.Description, vbCritical + vbOKOnly, "Une erreur est survenue" End Function
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 Private Sub MleEleve_BeforeUpdate(Cancel As Integer) If fEstEleveDejaComposant(Me.Identif_EtablisFR, _ Me.NumInsCreleve, Me.Mleeleve, Me.AnneeScol, _ Me.CompositionAra, Me.NiveauCompositionFrancais) = True Then MsgBox "ATTENTION !!" & vbCrLf & _ "Cet(Cette) élève est déjà " & vbCrLf & "enregistré(e) pour la" & _ Me.CompositionAra.Column(1) & "du " & _ Me.NiveauCompositionFrancais.Column(1), _ vbCritical + vbOKOnly, "Risque de Doublons" Undo End If End Sub
Cordialement.







Répondre avec citation










Partager