Bonjour,

Je fais appel à une fonction nommée Combien pour compter le nombre d'enregistrements d'une requête. Cette requête fait appel elle-même à une fonction de regroupement.

J'ai des soucis pour trouver la syntaxe exacte : bien qu'ayant consulté l'aide en ligne, je finis par ne plus savoir où je vais entre les doubles, voire triples guillemets , les Chr$(34), etc.

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
Function CouleurRelance()
    Dim NbEnreg As Long
    Dim sSQL As String
    sSQL = "SELECT tbl_UNITES.CUnite_ID, tbl_UNITES.Unite, tbl_AFFECTATIONS.Affectation, tbl_AGENTS.MAJ, tbl_AGENTS.Sortie, [Nom] & " " & PremMajMotsComp([Prenom]) AS Agent, tbl_GRADES.Grade, tbl_DEMANDES.CDemande_ID, tbl_CATEGORIES.Cat, tbl_CATEGORIES.Duree, tbl_DEMANDES.Formation, tbl_DEMANDES.Relance, DateSerial(Year([Formation]),Month([Formation])+[Duree],Day([Formation])) AS Validite " & _
           "FROM tbl_UNITES INNER JOIN (tbl_GRADES INNER JOIN (tbl_CATEGORIES INNER JOIN ((tbl_AFFECTATIONS INNER JOIN tbl_AGENTS ON tbl_AFFECTATIONS.CAffectation_ID = tbl_AGENTS.CAffectation) INNER JOIN tbl_DEMANDES ON tbl_AGENTS.Matricule_ID = tbl_DEMANDES.Matricule) ON tbl_CATEGORIES.CCategorie_ID = tbl_DEMANDES.CCategorie) ON tbl_GRADES.CGrade_ID = tbl_AGENTS.CGrade) ON tbl_UNITES.CUnite_ID = tbl_AFFECTATIONS.CUnite " & _
           "WHERE (((tbl_AGENTS.MaJ) = DMax("[MAJ]", "tbl_AGENTS")) And ((tbl_AGENTS.Sortie) > Date) And ((tbl_CATEGORIES.Duree) > 0) And ((tbl_DEMANDES.Formation) Is Not Null) And ((tbl_DEMANDES.Relance) Is Null) And ((DateSerial(Year([Formation]), Month([Formation]) + [Duree], Day([Formation]))) < Date)) " & _
           "ORDER BY tbl_UNITES.Unite;"
 
    NbEnreg = Combien("SELECT Count(*) FROM " & sSQL & ";")
 
    If ECF("frm_A_propos") = True Then
        If NbEnreg > 0 Then
            Forms![frm_A_propos]!recRelance.BackColor = 255
        Else
            Forms![frm_A_propos]!recRelance.BackColor = 32768
        End If
    End If
End Function
 
Function Combien(strSQL As String) As Long
    Dim oDb As DAO.Database
    Dim oRst As DAO.Recordset
    Set oDb = CurrentDb
    Set oRst = oDb.OpenRecordset(strSQL)
    Combien = oRst.Fields(0).Value
    oRst.Close
    oDb.Close
    Set oRst = Nothing
    Set oDb = Nothing
End Function
Je pense que l'erreur est à deux endroits. Tout d'abord ici
Code : Sélectionner tout - Visualiser dans une fenêtre à part
[Nom] & " " & PremMajMotsComp([Prenom])
puis là
Code : Sélectionner tout - Visualiser dans une fenêtre à part
DMax("[MAJ]", "tbl_AGENTS")
Quelqu'un pour me dépanner ?