0

I am new to Excel VBA. When I run the below code, I get an error "missing operator in query expression sum[Project Hrs]". What am I doing wrong?

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

1 Answer 1

4

It's not a VBA problem - it's an SQL problem. In the SUM part of your statement you haven't placed brackets.

strSQL = "Select [User Name], 
                 [Task Name], 
                 SUM([Project Hrs]) 
from             [idata$]      
group by         [User Name], 
                 [Task Name]"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.