Microsoft Access
--
Questions
--
Followers
Top Experts
Set rst = dbs.OpenRecordset("TempPoo
Set rst2 = dbs.OpenRecordset("Pool_Da
rst.MoveFirst
Do Until rst.EOF
  strRoute = rst!ROUTE_NUMBER
  rst2.Filter = "[ROUTE_NUMBER]='" & strRoute & "'"
  Set rstFiltered = rst2.OpenRecordset()
  rstFiltered.MoveLast
  stopcnt = rstFiltered.RecordCount
  rstFiltered.MoveFirst
    Do Until rstFiltered.EOF
      rstFiltered.Edit
      rstFiltered!TOTAL_STOPS = stopcnt
      rstFiltered.Update                <---------------------This
      eqsum = eqsum + rstFiltered!STOP_EQ
      rstFiltered.MoveNext
    Loop
  stopcnt = 0
  eqsum = 0
  rst.MoveNext
Loop
Any ideas will be appreciated.
ET
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
This is because you have two links to the db open at the same time,
what I would suggest is that you either do not use rst2 at all - and just requery each time you want to restrict the value - ie
set rst2 = dbs.OpenRecordset("select * from pool_Data where route_number = '" &Â strRoute &Â "';", dbopendynaset)
however what you are doing looks as though you would be able to do it with a simple update query, not worrying about stuffing around with recordsets.
>>>>>This is because you have two links to the db open at the same time,<<<<<
Are you referring to rst2 and rstFiltered which are both pointed to the Pool_Data table???
>>>what I would suggest is that you either do not use rst2 at all - and just requery each time you want to restrict the value - ie <<<<
Are you saying don use the rstFiltered and just requery rst2 based on the dynamic route number from rst???
Thanks,
ET
however I would recommend that you do this through SQL instead of VB - it would be faster and more reliable.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
I know I can use SQL but this is a migrated application from Access to MySQL and there's probably many cases where multiple recordsets have been opened in the code. Â I've just started to test the front end and I don't want to have to rewrite all those functions.
Set rst = dbs.OpenRecordset("TempPoo
rst.MoveFirst
Do Until rst.EOF
  strRoute = rst!ROUTE_NUMBER
  Set rst2 = dbs.OpenRecordset("select * from pool_Data where route_number = '" & strRoute & "';", dbOpenDynaset)
  rst2.MoveLast
  stopcnt = rst2.RecordCount
  rst2.MoveFirst
    Do Until rst2.EOF
      rst2.Edit
      rst2!TOTAL_STOPS = stopcnt
      rst2.Update   <-------------------------
      eqsum = eqsum + rst2!STOP_EQ
      rst2.MoveNext
    Loop
  rst.MoveNext
Loop
Thanks,
ET
U keep opening rst2 but I dont see where u close it after the loop. I wonder if because u keep opening these recordsets but not closing them, that might have a impact of some sort.
Also u shouldnt do a MoveLast straight away, instead check for EOF
eg
  Set rst2 = dbs.OpenRecordset("select * from pool_Data where route_number = '" & strRoute & "';", dbOpenDynaset)
 Â
  'NEW LINE if statement
  If rst2.EOF = False Then
    rst2.MoveLast
    stopcnt = rst2.recordCount
    rst2.MoveFirst
    Do Until rst2.EOF
      rst2.Edit
      rst2!TOTAL_STOPS = stopcnt
      rst2.Update
      eqsum = eqsum + rst2!STOP_EQ
      rst2.MoveNext
    Loop
 Â
  'NEW 2 LINES endif/close
  End If
  rst2.Close
   Â
  rst.MoveNext
it may not solve your problem but its something I believe u should do
Maybe there is something or a field setting in the table causing this or some other parameter that needs to be included on the OpenRecordset to eliminate this.
Function TestRST()
  Dim rst2 As Recordset, dbs As Database
  Set dbs = CurrentDb
  strRoute = "01000"
  Set rst2 = dbs.OpenRecordset("select * from pool_Data where route_number = '" & strRoute & "';", dbOpenDynaset)
  stopcnt = 1
  rst2.Edit
  rst2!TOTAL_STOPS = stopcnt
  rst2.Update   '<------------------------
End Function
Thanks,
ET

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
This tells me that that record or records is corrupted in that table and is why the recordset update is failing.
Question: Â Is it possible to repair that table in MySQL and if so how???
Thanks,
ET
I defined my variables by specifying the right model (DAO, ADO)
I reproduced your error by defining it like this
Dim rst2 As Recordset, dbs As Database
I originally I had it like this
Dim rst2 As DAO.Recordset, dbs As DAO.Database
and I never got the error
Tried that as well (see below) and still got the error message ...
I think it probably has something to do with the table in the MySQL backend but nothing stands out.  I even deleted the record that would not let me edit it directly in the front-end linked table to no avail.  The table has a PK which is the pool_id field and I added an additional ID auto increment  still to no avail.
Function TestRST()
  Dim rst2 As DAO.Recordset, dbs As DAO.Database
  Set dbs = CurrentDb
  strRoute = "01000"
  Set rst2 = dbs.OpenRecordset("select * from pool_Data where route_number = '" & strRoute & "';", dbOpenDynaset)
  stopcnt = 1
  rst2.Edit
  rst2!TOTAL_STOPS = stopcnt
  rst2.Update   '<------------------------
End Function






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Have u ever heard of Navicat? its a excellent tool for managing mysql databases
lets try an alternative way (also, can u confirm that route_number is defned as a string? and TOTAL_STOPS is numeric?)
set rst2 = dbs.OpenRecordset("pool_da
rst2.FindFirst "route_number = '" &Â strRoute &Â "'"
if rst2.NoMatch = True then
  msgbox "Record not found"
else
  rst2.Edit
  rst2!TOTAL_STOPS = 50
  rst2.Update
end if
Yes Route_number is Text/String and TOTAL_STOPS is numeric.
Even trying the alternative method I got the exact same results including the rst2.Close at the end of the function. Â It will run the very first time but the next time you execute the function the error will pop up about someone else is changing the data, etc. Â It's like once the recordset edits the table and closes the recordset MySQL still thinks the table/record is being edited. Â Strange but I'm trying to make this work with the Recordset option because I know there are many more functions that's doing the same thing and I really don't want to go in and re-write all of them.
  Set rst2 = dbs.OpenRecordset("pool_da
  rst2.FindFirst "route_number = '" & strRoute & "'"
  If rst2.NoMatch = True Then
  MsgBox "Record not found"
  Else
  rst2.Edit
  rst2!TOTAL_STOPS = 50
  rst2.Update
  rst2.Close
  End If
I know how to dump the entire db using mysqldump but not really sure how to create a schema of just that table plus this is a large table with lots of fields (60+).
ET
Hummm, Â I see the pattern now. Â I ran into this before with a control on a form being updated from a subform where the recordsource was tied to a MySQL Backend. Â It's real weird and I never found a solution or explanation as to why this happens.
Here goes ....
When the recordset is updating a field in the MySQL backend, if the value in the field (TOTAL_STOPS) in this case will actually be changed by the update (meaning not the same) then the recordset update will work without generating the error. Â If the value in the field will remain the same as what the recordset is trying to update it to then it's like MySQL doesn't do anything and is left in a state where it thinks the record is still being edited.
I'm sure there is a way to get around something that seems so simple but who knows. Â
ET

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
only update if the values differ
I remember your last question, yes weird one that.
I posted another related question to see if anyone else has run into this problem.
Thanks,
ET






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Now that is strange. I wonder if there is a bug in MySQL
I tried the example using ADO and its the same problem.
Im checking mysql support to see if there is anything
Also read somewhere about service packs, Im assuming you have all the latest windows service packs and latest mysql
"Return Matching Rows" is the answer. Â Once checked on in the DSN the Recordset Update works as intended without generating the error.
Much appreciated rocki and I owe you one big time.
Thanks,
ET

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Microsoft Access
--
Questions
--
Followers
Top Experts
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.