Docmd.openquery causes error

D

dkschoonover

I have a Make-Table Query "Repair"

When I double click the query to run it, it creates the table appropriately.

When I add it to a command button, it causes an error:
The database engine could not lock table "repairx" because it is already in
use by another person or process."

There is no one else in my test environment.

My code string looks like:
DoCmd.Close
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.OpenQuery stDocName2, acNormal, acEdit
DoCmd.OpenQuery StDocName3, acNormal, acEdit
DoCmd.OpenQuery StDocName4, acNormal, acEdit
DoCmd.RunMacro "Google Earth Export"
DoCmd.OpenQuery StDocName6, acNormal, acEdit
DoCmd.RunMacro "VSAT Validation Export"
=> DoCmd.OpenQuery "Repair", acViewNormal, acAdd
MsgBox ("Updates Complete")
DoCmd.OpenForm stDocName9, , , stLinkCriteria

I have tried it as acAdd and acEdit.

Any ideas?
 
K

Ken Snell \(MVP\)

Is the form that has the command button a form that is bound to the Repair
table? If yes, that is where the locking is coming from. Check this setting
in Record Locks property for the form and be sure that it's set to No Locks.
 
D

dkschoonover

The DoCmd.Close is closing the form before the queries run, so the only thing
open is the database window (showing the list of tables, etc.).

I checked the form which contains the command button, and all of the
subforms; they are all marked "No Locks"

Darryl
 
D

dkschoonover

Solved it - the issue was because the Query and the Table had the same name -
the Query didn't know what to do!!
 
K

Ken Snell \(MVP\)

It's unfortunate that ACCESS lets you name a table and a query with the same
name. That does cause confusion, as you've found. Good practice to ensure
that each object in your database has a unique name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top