我是Excel VBA的新手。当我运行下面的代码时,我得到一个错误“在查询表达式sum [Project Hrs]中缺少运算符”。我做错了什么?
Sub TaskHrs()
strSQL = "Select [User Name], [Task Name], sum[Project Hrs] from [idata$] group by [User Name], [Task Name]"
closeRS
OpenDB
rs.Open strSQL, cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
Do While Not rs.EOF
Range("A1").CopyFromRecordset rs
Loop
End If
End Sub
答案 0 :(得分:4)
这不是VBA问题 - 它是一个SQL问题。在陈述的SUM部分,您没有放置括号。
strSQL = "Select [User Name],
[Task Name],
SUM([Project Hrs])
from [idata$]
group by [User Name],
[Task Name]"