Bonjour,

J'ai un problème de syntaxe, j'espère que quelqu'un pourra m'aider.

voici le tableau que j'avais :

AnneeEffet Quartile
2001 23,25
2002 24,56
2003 21,58
2004 24,59
2005 29,45
2006 30,14

Que je faisais avec le code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Function Quartil(strTable As String, strField As String, param As String, anne As integer, rang As Integer) As Double
[...]  Set oRST = oDBS.OpenRecordset("SELECT * FROM " & strTable & " WHERE " & param & " = " & anne & " ORDER BY " & strField)
[...]
Maintenant, il a été décidé dans le service, que le tableau serait :

N-4 et avant 24,26
N-3 21,58
N-2 24,59
N-1 29,45
N 30,14

Donc l'année en format integer, devient un string. Et je n'arrive absolument pas à faire fonctionner la fonction qui marchait très bien !

Voila comment j'appelais la fonction avant :
Q1_AgeSous: Quartil("GRBR_Nettoyé_en_cours_access";"[AGESOUS]";"[AnneeSOUS]";[AnneeSOUS];1)

Comment changer cette syntaxe pour que l'année de souscription soit prise comme un string ?

Voici la fonction est entier : (j'ai changé anne as string et dans le SELECT je n'arrive pas à faire le changement adéquat)

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
Function Quartil(strTable As String, strField As String, param As String, anne As String, rang As Integer) As Double
 
Dim oDBS As DAO.Database
Dim oRST As DAO.Recordset
Dim blnEven As Boolean
Dim vntMedian As Variant
 
If rang = 1 Then rang = 25
If rang = 3 Then rang = 75
 
  Set oDBS = CurrentDb()
  Set oRST = oDBS.OpenRecordset("SELECT * FROM " & strTable & " WHERE " & param & " = " & anne & " ORDER BY " & strField)
 
  If oRST.EOF = False Then
     oRST.MoveLast
     'Is there an even number of records in the recordset?
     blnEven = (oRST.RecordCount Mod 2 = 0)
     'Rounds down if there is an even number of records...
     oRST.PercentPosition = rang
     vntMedian = oRST.Fields(strField)
     If blnEven Then
         oRST.MoveNext
         '...so take the average of the this and the next value up
         vntMedian = (vntMedian + oRST.Fields(strField)) / 2
     End If
  End If
 
  Quartil = vntMedian
  oRST.Close
  Set oRST = Nothing
  Set oDBS = Nothing
 
End Function