The query statement looks fine.
I don't use ADO, but I suspect the CommandText has to be a SQL statement,
not the name of a query. You could point the command to the member of the
Procedures() and execute that. Alternatively, put the entire query statement
in a string, and set that to the CommandText.
As another alternative, exeucte it under DAO:
With DBEngine(0)(0)
.Execute .QueryDefs("qry_cl_sum"), dbFailOnError
End With
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Reply to group, rather than allenbrowne at mvps dot org.
Becky said:
Hi - here is the code:
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "qry_cl_sum"
cmd.Execute
and here is the SQL of the query:
INSERT INTO tbl_cl ( [Year], Company, LOB, COIType, WithdrawalGroup, IG,
cvcd, pnpi, istm, iage_band, sexi, atage_band, dur_band, dur_band2, smoke,
jtin, jage, blfq, bstl, anum, aamt, enum, eamt, xnum, xamt, polsize_ind )
SELECT tbl_cl_all.Year, tbl_cl_all.Company, tbl_cl_all.LOB,
tbl_cl_all.COIType, tbl_cl_all.WithdrawalGroup, tbl_cl_all.IG,
tbl_cl_all.cvcd, tbl_cl_all.pnpi, tbl_cl_all.istm, tbl_cl_all.isage_band,
tbl_cl_all.sexi, tbl_cl_all.atage_band, tbl_cl_all.dura_band,
tbl_cl_all.dura_band2, tbl_cl_all.smoke, tbl_cl_all.jtin, tbl_cl_all.jage,
tbl_cl_all.blfq, tbl_cl_all.bstc, Sum(tbl_cl_all.anum) AS SumOfanum,
Sum(tbl_cl_all.aamt) AS SumOfaamt, Sum(tbl_cl_all.enum) AS SumOfenum,
Sum(tbl_cl_all.eamt) AS SumOfeamt, Sum(tbl_cl_all.xnum) AS SumOfxnum,
Sum(tbl_cl_all.xamt) AS SumOfxamt, tbl_cl_all.polsize_ind
FROM tbl_cl_all
GROUP BY tbl_cl_all.Year, tbl_cl_all.Company, tbl_cl_all.LOB,
tbl_cl_all.COIType, tbl_cl_all.WithdrawalGroup, tbl_cl_all.IG,
tbl_cl_all.cvcd, tbl_cl_all.pnpi, tbl_cl_all.istm, tbl_cl_all.isage_band, tb
l_cl_all.sexi, tbl_cl_all.atage_band, tbl_cl_all.dura_band,
tbl_cl_all.dura_band2, tbl_cl_all.smoke, tbl_cl_all.jtin, tbl_cl_all.jage,
tbl_cl_all.blfq, tbl_cl_all.bstc, tbl_cl_all.polsize_ind;
The query works outside of the VBA code perfectly fine, but I get the
Invalid SQL statement error when executing it in the code.