runtime error 3122

Gregorys05

Board Regular
Joined
Sep 24, 2008
Messages
217
Hi Guy's
I have the below SQL query and i keep getting runtime error 3122

You tried to execute a query that doesn't include the specified expression as part of an aggregate function.

can any one please help

Private Sub Form_Open(Cancel As Integer)

Dim xxx As String

Dim sql As String

If Forms![frmContractFileUploadNew(SG Testing)]!optPropertyType = 1 Then xxx = "Not Like " Else xxx = "Like "

sql = "SELECT tblPlannedWork.fldContractorCode, tlkpYear.fldFinancialYear, tblReportingPeriod.fldMonth, tblElement.fldElement, Count(tblPlannedWork.fldPropertyRef) AS [Total Elements Complete] " & _
" FROM ((tblPlannedWork INNER JOIN tblElement ON tblPlannedWork.fldElementID = tblElement.fldElementID) INNER JOIN tblReportingPeriod ON tblPlannedWork.fldReportingPeriod = tblReportingPeriod.fldReportingPeriodCode) INNER JOIN tlkpYear ON tblReportingPeriod.fldYear = tlkpYear.fldYear " & _
" WHERE (((tblPlannedWork.fldCAStatusID) In (2,3)) AND ((tblReportingPeriod.fldYear) In (select [fldCurrentYear] FROM [tlkpCurrentYear]) Or (tblReportingPeriod.fldYear)=2009)) OR (((tblReportingPeriod.fldYear) In (select [fldCurrentYear] FROM [tlkpCurrentYear]) Or (tblReportingPeriod.fldYear)=2009) AND ((tblPlannedWork.fldContractorCode)='one')) " & _
" GROUP BY tblPlannedWork.fldContractorCode, tlkpYear.fldFinancialYear, tblReportingPeriod.fldMonth, tblElement.fldElement, tblReportingPeriod.fldYear, tblReportingPeriod.fldReportingPeriodCode, tblElement.fldElementID, tblPlannedWork.fldProgrammeYear, tblPlannedWork.fldContractorStatusID, tblPlannedWork.fldSEHStatusID " & _
" HAVING (((tblPlannedWork.fldContractorStatusID)=8) AND ((tblPlannedWork.fldSEHStatusID)=11) AND ((tblPlannedWork.fldPropertyRef) " & xxx & " 'bc*')) OR (((tblPlannedWork.fldContractorStatusID)=8) AND ((tblPlannedWork.fldSEHStatusID)=11) AND ((tblPlannedWork.fldPropertyRef) " & xxx & " 'bc*')) " & _
" ORDER BY tblPlannedWork.fldContractorCode, tlkpYear.fldFinancialYear, tblReportingPeriod.fldMonth, tblReportingPeriod.fldYear, tblReportingPeriod.fldMonth;"

Debug.Print sql

Me.RecordSource = sql
Me.Requery
'DoCmd.OpenQuery stDocName, acNormal, acEdit

End Sub
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Watch MrExcel Video

Forum statistics

Threads
1,122,517
Messages
5,596,620
Members
414,081
Latest member
Subaru_Steve

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top