We help IT Professionals succeed at work.

Getting an Invalid Operation error when code executed from inside an MS Access vba routine

pcalabria asked
Last Modified: 2018-10-17
I'm getting an invalid operation message when the following line of code is executed:

                strSQLtext = "UPDATE ComponentMaster SET OrderNumberNoSync = true  WHERE searchnumber='" & strSearchNumber & "' And LineID = " & oRS!LineID
                Set oRS2 = oDB.OpenRecordset(strSQLtext)

When I print strSQLtext in the immediate window, then copy it to a query outside the routine, it runs without issue.
Watch Question

Distinguished Expert 2017
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)


@Fabrice  Thanks and thanks for the explanation.  I'm sure now I'll remember but the code provided still does not work.  I get a message that says "Could not update; record locked".  I suspect this is because I am cycling though a recordset and now trying to change one of the records in that recordset (but not the recordset at the cursor).  Can you help?
Distinguished Expert 2017

You may have cut off too much of the code.  Put a stop in the code and print the SQL string to the immediate window.  If you don't see the problem, copy it and paste it into the QBE and try to run it from there.

Based on the error message, chances are excellent that the form that is running this code is bound to the form that is running it and the current record is dirty.
Fabrice LambertConsulting
Distinguished Expert 2017

Well, this is another issue, not related to your first question.

Close this post and open a new one.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions