我正在遵循一直给出语法错误的 VBA 代码。有人可以帮我找出导致错误的原因吗?
Private Sub Command11_Click()
Dim EndingDate As Date
'Getting ending date from Label named endDate
EndingDate = endDate
StartingDateTxt = DateSerial(Year(EndingDate), Month(EndingDate) - 15, Day(EndingDate))
Dim customerRecords As New ADODB.Recordset
customerRecords.Open "SELECT COUNT(*) AS N FROM (SELECT DISTINCT E.Date,"&_
"E.[Inv Num], E.CusName, E.[Name Street1], E.[Name Street2], "&_
"E.[Name City], E.[Name State], E.[Name Zip], E.[Account #], E.Amount FROM TempFromExcel "&_
"AS E INNER JOIN TempFromExcel AS X ON E.CusName = X.CusName "&_
"WHERE (((DateDiff("d",X.Date,E.Date))>=30)) AND E.Date >= '" & StartingDateTxt & "' and"&_
"E.Date <= '" & endDate & "') AS T ;", _
CodeProject.Connection , _
adOpenStatic, _
adLockOptimistic, _
adCmdText
MsgBox customerRecords("N")
End Sub
我的查询正在获取两个日期并查找两个日期之间的结果。
我想我可能只在那个部分失踪了。其余的似乎很好,因为我已经明确检查了查询并且它运行良好。这是对的吗?
E.Date >= '" & StartingDateTxt & "' and E.Date <= '" & endDate & "'
这已在答案中得到纠正,但在 Select 语句的第一行中仍然出现语法错误。错过了什么吗?