Bonjour,

Je souhaite transcrire une requête SQL en VBA à des fins d'automatisation et j'ai donc le code suivant :

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
 
Public Sub REPONSE(ByVal noetude As String, strsql As String)
 
Dim strtable As String
Dim strcriteria As String
 
strtable = "CARACATT, ETUDES, QUESTIONS, MODALITES"
strcriteria = "CARACATT.no_etude in (" & noetude & ")"
strcriteria = strcriteria & " And CARACATT.no_etude=ETUDES.no_etude And CARACATT.reponse=MODALITES.modalite AND CARACATT.question=MODALITES.question and ETUDES.no_etude=MODALITES.no_etude and QUESTIONS.question=MODALITES.question and QUESTIONS.no_etude=MODALITES.no_etude"
strcriteria = strcriteria & " And (CARACATT.question)='INTENTION DE RECONSOMMATION'"
strsql = "SELECT ETUDES.type_produit, CARACATT.no_produit, CARACATT.question, CARACATT.reponse, IIf([modalite_max]=5 And ([reponse]='1' Or [reponse]='2'),'1',IIf([modalite_max]=5 And ([reponse]='4' Or [reponse]='5'),'2',IIf([modalite_max]=4 And ([reponse]='1' Or [reponse]='2'),'1',IIf([modalite_max]=4 And ([reponse]='3' Or [reponse]='4'),'2',IIf(([modalite_max]=2 Or [modalite_max]=3) And [codage]=NON And [reponse]='2','2',IIf(([modalite_max]=2 Or [modalite_max]=3) And [codage]='NON' And [reponse]='1','1',IIf(([modalite_max]=2 Or [modalite_max]=3) And [codage]='OUI' And [reponse]='2','2',IIf(([modalite_max]=2 Or [modalite_max]=3) And [codage]='OUI' And [reponse]='1','1',IIf(([modalite_max]=3 Or [modalite_max]=5) And ([codage]='JE NE SAIS PAS' Or [codage]='JE NE SAIS SI JE L'ACHETERAIS OU NON') And [reponse]='3','3'))))))))) AS REPONSE_CARACATT, QUESTIONS.modalite_max, MODALITES.codage INTO REPONSE"
strsql = strsql + " FROM " & strtable
strsql = strsql + " WHERE ((" & strcriteria & "))"
strsql = strsql & " GROUP BY ETUDES.type_produit, CARACATT.no_produit, CARACATT.question, CARACATT.reponse, QUESTIONS.modalite_max, MODALITES.codage;"
 
End Sub
Mon problème est que ACCESS me met un message d'erreur "ERREUR DE SYNTAXE : OPERATEUR ABSENT"...

J'ai retourné la requête dans tous les sens mais je vois pas : je fais donc appel à un oeil extérieur pour trouver mon erreur !

Quelqu'un voit où sa plante ???

Merci de vos réponses...