I’m migrating an Access Database to MySQL.
Most of the program works well but I still have a problem with an SQL query.
I obtain a 3197 Run Time Error :
The Microsoft Office Access database engine stopped the process because you and another user are attempting to change the same data at the same time.
What I have already done :
- Configure my ODBC Driver to allow Dynamic Cursors
- Configure my ODBC Driver to return matched rows instead of affected rows
The code which causes the error :
Dim rsMain As Recordset
Dim rs As Recordset
Dim db As Database
Set db = CurrentDb
Dim sqlQuery As String
sqlQuery = "Select * from Table1 where field1 like '" & Me.field10 & "*' and field2=" & Me.field11 & " and field3=True"
Set rsMain = db.OpenRecordset(sqlQuery)
rsMain.MoveFirst
Do Until rsMain.EOF
sqlQuery = "select sum(field4) as Est, sum(field5) as Cons, sum(field6) as Prod from Table1 where field1 like '" & rsMain("field1") & "*' and field3=False and field5=" & Me.modifiedDate
Set rs = db.OpenRecordset(sqlQuery)
rsMain.Edit
rsMain.Fields("field4") = rs.Fields("Est")
Set rs = Nothing
rsMain.Update
rsMain.MoveNext
Loop
Set rsMain = Nothing
The rsMain.Update command fails, it’s where the error come from.
I have similar code which don’t cause any error. I am the only user at the time.
Thanks in advance for your insights
Instead of the
rsMain.Edit/UpdateI used directly the SQL update usingDoCmd.RunSQL SQLQuerywhere SQLQuery is my updated SQL query.