-
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.
-
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?
-
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.
-
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.