我还没有找到答案或解决方案,我希望有人可以帮助我。以下SQL语句运行完美,并在从Access中的查询运行时返回所需的结果(Create => Query Design =>在SQL视图中粘贴)。
SELECT DISTINCT Table1.ITMID
FROM Table1
INNER JOIN Table2 ON ((PRTID) = (Table1.ITMID)) AND ((Table2.PLT) = (Table1.PLT))
WHERE (((Table1.PLT) = '" & pltflag & "') AND ((Table1.MAKBUYIND) = 'M') AND ((Table2.ENDEFF) = 99999) AND ((Table2.CMPTYP) = 'E'))
ORDER BY Table1.ITMID;
但是,当我尝试使用以下代码从Excel VBA运行查询时
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sSQL As String
Set db = OpenDatabase(g400DBPath)
sSQL = "SELECT DISTINCT Table1.ITMID FROM Table1 INNER JOIN Table2 ON ((PRTID) = (Table1.ITMID)) AND ((Table2.PLT) = (Table1.PLT)) WHERE (((Table1.PLT) = '" & PltFlag & "') AND ((Table1.MAKBUYIND) = 'M') AND ((Table2.ENDEFF) = 99999) AND ((Table2.CMPTYP) = 'E')) ORDER BY Table1.ITMID;"
Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
尝试执行带有以下错误的语句时失败
Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot)
运行时错误:3296 加入表达式不支持