M.iaou
M.iaou

Reputation: 27

Error on sql request on access vba

I've an error on this code:

 Promo_var = Modifiable84.Value
   MsgBox Promo_var

   DoCmd.Hourglass True 'icone tablier a true

   ' set to break on all errors
   Application.SetOption "Error Trapping", 0

   ' start with a clean file built from the template file
   sTemplate = CurrentProject.Path & "\PlanificationAnnuelle_Template.xlsx"
   sOutput = CurrentProject.Path & "\PlanificationAnnuelle.xlsx"
   If Dir(sOutput) <> "" Then Kill sOutput
   FileCopy sTemplate, sOutput

   ' Create the Excel Applicaiton, Workbook and Worksheet and Database object
   Set appExcel = New Excel.Application
   Set wbk = appExcel.Workbooks.Open(sOutput)
   Set wks = appExcel.Worksheets(cTabTwo)

   sSQL = "SELECT Nom, PROMO, Semestre1A, Semestre1B, Semestre2A, Semestre2B, CatSemestre1A, CatSemestre1B, CatSemestre2A, CatSemestre2B FROM Planif WHERE CatSemestre1A > 0 OR CatSemestre1B > 0 OR CatSemestre2A > 0 OR CatSemestre2B > 0 WHERE PROMO = '" & Promo_var & "' ORDER BY Nom ASC "
   MsgBox sSQL
   Set dbs = CurrentDb
   Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)

The error occurs on these line:

Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)

The error is error

'3075' Syntax error (missing operator)

I can't find where is the problem. i've tried several sql change but i'm loose

Upvotes: 2

Views: 47

Answers (1)

Fleury26
Fleury26

Reputation: 585

You call WHERE two times in your query

SELECT Nom, PROMO, Semestre1A, Semestre1B, Semestre2A, Semestre2B, CatSemestre1A, CatSemestre1B, CatSemestre2A, CatSemestre2B 
FROM Planif 
WHERE CatSemestre1A > 0 OR CatSemestre1B > 0 OR CatSemestre2A > 0 OR CatSemestre2B > 0 
WHERE PROMO = '" & Promo_var & "' 
ORDER BY Nom ASC 

Upvotes: 4

Related Questions