PDA

Click to See Complete Forum and Search --> : Help ADO INSERT Error


UKPhil
Apr 9th, 2000, 08:16 PM
I'm trying to run an INSERT INTO SQL query using the ADO recordset object. The SQL string uses lots of variables but these are correct as this procedure works fine as a SELECT query or as a SELECT INTO query.

strAssignMonth = Format(DateAdd("m", 0, frmDates.datRFrom), "yymm")
strSQL = "INSERT INTO QUERY SELECT EMPNO,Cstr(FRDATE) as RDATE,Cstr(LOGDATE) as CDATE,Left([LOGTIME],Len([LOGTIME])-4) as CTIME,LOGTYPE,IDENTITY,ACTCODE "
strSQL = strSQL + "FROM LASG" & strAssignMonth & " WHERE (EMPNO='" & strEmpCode & "') "
strSQL = strSQL + "AND (FRDATE Between {ts '" & frmDates.strRDateFrom & " 00:00:00'} "
strSQL = strSQL + "and {d '" & frmDates.strRDateTo & "'}) AND (LOGDATE Between {d '" & frmDates.strCDateFrom & "'} "
strSQL = strSQL + "and {d '" & frmDates.strCDateTo & "'}) AND (LOGTYPE Not In ('SPL','UPD')) "
strSQL = strSQL + "ORDER BY EMPNO ASC, FRDATE ASC, LOGDATE ASC, LOGTIME ASC, LOGTYPE ASC;"

rsQuery.Open strSQL, frmFront.cn, adOpenStatic, adLockReadOnly

I keep getting the error: Operation must use an updateable query. As I say, the syntax as far as I know is fine as it works as a SELECT and SELECT INTO query, but not as a INSERT INTO.

Any help gratefully received.

Thanks in advance.

HarryW
Apr 9th, 2000, 08:25 PM
Umm, I have a vague idea of what all that code does, so I'm just making an observation here.

If it says it needs an updateable query, would it help to open the recordset as read/write instead of read-only?

UKPhil
Apr 9th, 2000, 08:39 PM
Hi Harry,

Thanks for the quick reply. I'm new to ADO so I tried using all the different properties at the end of the recordsey.open command including adLockPessimistic etc and I still got the same message.

Ianpbaker
Apr 9th, 2000, 10:27 PM
try using frmFront.cn.execute strsql

this does the insert straight into the database without using a recordset and is the way I always do inserts and should sort out your problem.