Query works ok but not in code

B

Becky

Hi - I have an append query that basically just takes a bunch of data from one table, does some manipulation on it and then appends it to another table. It works fine if I run the query manually but when I try to run it in code I get Run-time error '-2147217900 (80040e14)': Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'. Here's my code

Dim gdb As ADODB.Connectio
Set gdb = New ADODB.Connectio
Set gdb = CurrentProject.Connectio
gdb.Execute "qry_cl_data

The sql of my query is

INSERT INTO tbl_cl_data_plus_actuals ( [Year], company, LOB, COIType, WithdrawalGroup, cvcd, pnpi, istm, isage, isage_band, sexi, sexi_orig, atage, atage_band, dura, dura_band, dura_band2, smoke, jtin, blfq, bstc, polsize_ind, product, enum, eamt, anum, apamt, epamt
SELECT tbl_cl_data.Year, tbl_cl_data.company, IIf([product_type]="ULF","UL","TR") AS Expr1, tbl_cl_data.COIType, tbl_cl_data.WithdrawalGroup, IIf([product_type]="ULF","UL",[perm_term]) AS Expr3, tbl_cl_data.par_nonpar, tbl_cl_data.Rating, tbl_cl_data.issue_age, ia([issue_age]) AS Expr6, IIf([sex]="J","M",[sex]) AS Expr16, tbl_cl_data.sex, tbl_cl_data.attained_age, aab([attained_age]) AS Expr7, tbl_cl_data.duration, db([duration]) AS Expr8, db2([duration]) AS Expr20, smk([smoker_status],[issue_age]) AS Expr9, jnt_ind([joint_ind]) AS Expr10, blfq([premium_frequency]) AS Expr12, "Broker" AS Expr11, ps([benefit]) AS Expr15, tbl_cl_data.product, tbl_cl_data.enum, tbl_cl_data.eamt, 0 AS Expr2, 0 AS Expr4, 0 AS Expr
FROM tbl_cl_dat
WHERE (((tbl_cl_data.sex)="M" Or (tbl_cl_data.sex)="F" Or (tbl_cl_data.sex)="J"))

I have no idea why this won't work. I have another database that does similar things and it works fine. HELP!!

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top