我对此代码有错误:
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)
这些行发生错误:
Set rst = dbs.OpenRecordset(sSQL, dbOpenSnapshot)
错误是错误
'3075'语法错误(缺少运算符)
我找不到问题所在。 我已经尝试了几次sql更改,但我很松散
答案 0 :(得分:4)
您在查询中两次致电WHERE
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