MS Access VBA Error 3211 "The database engine could not lock table", (1 Viewer)

lhooker

Registered User.
Local time
Today, 03:10
Joined
Dec 30, 2005
Messages
399
I have a macro that's giving me a 3211 error. How can I find out which form, table, or query in the macro is open ?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:10
Joined
Feb 28, 2001
Messages
27,186
What was the macro trying to do at the time?

Finding an open form involves recognizing that the Forms collection has certain properties. If you can get to a place where you can open the Immediate window, then do a debug.print on some things, you might be able to tell.

Debug.Print Forms.Count will tell you how many forms are open. Remember that Access collections start counting at 0, so...
Debug.Print Forms(0).Name will tell you the first name.
Debug.Print Forms(1).Name will tell you the second name and so on.

Recordsets are in the database engine. You can try this.

Debug.Print Database.Recordsets.Count will tell you how many are open at the moment.
Debug.Print Database.Recordsets(0).Name will tell you the name of the first recordset, OR if it was an SQL statement, the first 256 characters of the SQL. Again, counting starts from 0.

Debug.Print Database.Recordsets(0).Connect will tell you the connection string for the first recordset if it points to external database files or engines.
 

isladogs

MVP / VIP
Local time
Today, 08:10
Joined
Jan 14, 2017
Messages
18,221
AFAIAA, you cannot use Debug.Print in an Access macro though you could put a message box after each step

However, Access Error 3211 is:
The database engine could not lock table (YOUR TABLE NAME HERE) because it is already in use by another person or process.

If that still isn't clear enough, then run your macro using single step to identify where exactly it fails
 

tvanstiphout

Active member
Local time
Today, 00:10
Joined
Jan 22, 2016
Messages
222
What was the macro trying to do at the time?

Finding an open form involves recognizing that the Forms collection has certain properties. If you can get to a place where you can open the Immediate window, then do a debug.print on some things, you might be able to tell.

Debug.Print Forms.Count will tell you how many forms are open. Remember that Access collections start counting at 0, so...
Debug.Print Forms(0).Name will tell you the first name.
Debug.Print Forms(1).Name will tell you the second name and so on.

Recordsets are in the database engine. You can try this.

Debug.Print Database.Recordsets.Count will tell you how many are open at the moment.
Debug.Print Database.Recordsets(0).Name will tell you the name of the first recordset, OR if it was an SQL statement, the first 256 characters of the SQL. Again, counting starts from 0.

Debug.Print Database.Recordsets(0).Connect will tell you the connection string for the first recordset if it points to external database files or engines.
@TheDocMan: you probably meant:
Debug.Print CurrentDB.Recordsets.Count
(or replace CurrentDB with whatever Database variable you already have in place)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 02:10
Joined
Feb 28, 2001
Messages
27,186
Your correction is noted, Tom. Had the idea right, but not the proper object. But it WAS kind of late when I replied to that.
 

Users who are viewing this thread

Top Bottom