Delete corrupt table - Error database engine could not lock table (1 Viewer)

amaklop

Registered User.
Local time
Today, 07:13
Joined
Sep 6, 2018
Messages
17
Hi

I have a table with a corrupt record (Chinese character in one of the columns). I'm trying write code to resolve this should it happen again. I know ... we should rather try to ensure the db doesn't become corrupted .. however ours still manage to be from time to time.

So the corrupt record is GrnID = 3 in the T_GoodsReceivedNotes table. GrnID is the primary key, autonumber of the T_GoodsReceivedNotes table.

So I figured if I make a copy of the corrupt table excluding the corrupt record then the copy of the table will be clean. Then I can drop the corrupt table, rename the temp table and Bob's your uncle.

So I've managed to successfully :
a) Identify the corrupt record
b) Make a copy of the corrupt table excluding the bad record

However when I try to drop the corrupt table I get the following error :

The database engine could not lock table 'T_GoodsReceivedNotes' because it is already used by another person or process

I did originally think it was as the error said being used by another person or process but after closing the back end database (the tables are in the back end by the way) as well as all the forms in the front end database it was still giving the error. I dropped another random table on the back end database just to check the db wasn't opened twice and it dropped successfully. So my conclusion is that it's not dropping it because of the bad record.

Any ideas.

Here is the code.

Set db = OpenDatabase("C:\Matrix\Matrix_be.accdb")
db.Execute "Select into Temp_GoodsReceivedNotes From T_GoodsReceivedNotes where GrnId <> " & RecKey
db.Execute "drop table T_GoodsReceivedNotes"
db.Execute "SELECT * INTO T_GoodsReceivedNotes FROM Temp_GoodsReceivedNotes"
db.Execute "drop table Temp_GoodsReceivedNotes"
db.Close
 

amaklop

Registered User.
Local time
Today, 07:13
Joined
Sep 6, 2018
Messages
17
Sorry, I'm new to this. Is my thread/question still "active" or do I need to post a new one?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:13
Joined
Feb 19, 2013
Messages
16,614
no - just understand that responders are volunteers giving their time freely and don't appreciate having it wasted.

I was going to respond and suggest copy to a new db - but see that has already been asked on the other forum - so I wont be responding:)
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 09:13
Joined
Feb 28, 2001
Messages
27,187
I'm going to presume you have tried a "compact & repair" on a copy of the database?
 

Users who are viewing this thread

Top Bottom