pattynewbie
Programmer
I'm new to access code and I have the following query that works but I need to put it in code. The follow query works but my code has syntax errors and I'm not quite sure how to
fix it.
Any help would be appreciated.
(Query)
INSERT INTO TSumActHrs ( SumOfHr, CN, TargetCode )
SELECT Sum(ENGHOURS.Hr) AS SumOfHr, ENGHOURS.CN, IIf([dcl]="B",5,0) AS TargetCode
FROM ENGHOURS
WHERE (((ENGHOURS.DCL)="B") AND ((ENGHOURS.CC)=1))
GROUP BY ENGHOURS.CN, IIf([dcl]="B",5,0)
HAVING (((ENGHOURS.CN)=[me].[jobnumber]));
(Code)
strSQL = "INSERT INTO TSumActHrs ( SumOfHr, CN, TargetCode )" _
& " SELECT Sum(ENGHOURS.Hr) AS SumOfHr, ENGHOURS.CN, IIf([dcl]='B',5,0 AS TargetCode" _
& " FROM ENGHOURS" _
& " WHERE (ENGHOURS.DCL)='B' And ((ENGHOURS.CC) = 1))" _
& " GROUP BY ENGHOURS.CN, IIf([dcl]= 'B',5,0)" _
& " HAVING (ENGHOURS.CN)= '" & Me.Jobnumber & "';"
db.Execute strSQL
fix it.
Any help would be appreciated.
(Query)
INSERT INTO TSumActHrs ( SumOfHr, CN, TargetCode )
SELECT Sum(ENGHOURS.Hr) AS SumOfHr, ENGHOURS.CN, IIf([dcl]="B",5,0) AS TargetCode
FROM ENGHOURS
WHERE (((ENGHOURS.DCL)="B") AND ((ENGHOURS.CC)=1))
GROUP BY ENGHOURS.CN, IIf([dcl]="B",5,0)
HAVING (((ENGHOURS.CN)=[me].[jobnumber]));
(Code)
strSQL = "INSERT INTO TSumActHrs ( SumOfHr, CN, TargetCode )" _
& " SELECT Sum(ENGHOURS.Hr) AS SumOfHr, ENGHOURS.CN, IIf([dcl]='B',5,0 AS TargetCode" _
& " FROM ENGHOURS" _
& " WHERE (ENGHOURS.DCL)='B' And ((ENGHOURS.CC) = 1))" _
& " GROUP BY ENGHOURS.CN, IIf([dcl]= 'B',5,0)" _
& " HAVING (ENGHOURS.CN)= '" & Me.Jobnumber & "';"
db.Execute strSQL