Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compact database programmatically

Status
Not open for further replies.

easycode

Programmer
Jan 28, 2005
195
US
I need to compact a database programmatically, i have checked all the faqs, none help.

I need the new compacted file to overwrite the no compacted file when i use the next instruction:

DBEngine.CompactDatabase "C:\DB\mydb.mdb", "C:\DB\mydb.mdb"

i get this error:

"You attempted to open a database that is already opened exclusively by user 'Admin' on machine 'FL50144'. Try again when the database is available.
and i heard that is because when access open a database it automatically creates an ldb security file, but this file can not be deleted.

Can anyone advice?

Thanks
 
possibly this,
Docmd.RunCommand acCmdCompactDatabase
 
I tried both suggestions and i am getting this error message:

"You can't compact the open database while running a macro or Visual Basic code.

looks like it's not possible to compact a database programatically because of the ldb file.
 
i just opened the database in an exclusive mode where there isn't a ldb file and i am still getting the same error message, so the error is not based on the ldb file but i think it just can't be done programatically!
 
Sorry MS2000, I never tried it until now, just assumed.
Maybe it's only functional for remote connections?
 
Seabz420, the thread you mentioned use the same code as the link I posted.
 
Run the code that you have from a different database. Don't run it within tha database tha you are trying to compact.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top