Click to See Complete Forum and Search --> : Compact & repair database
anilgoje
Nov 21st, 2000, 04:19 PM
Hi,
I know that we can compact and repair database with Tools>database utilities>compact& repair database option,but can anyone tell me as is it possible to do this with the code.Iam using Access2000
Any help will be highly appreciated.
Regards
Lafor
Nov 21st, 2000, 04:31 PM
try this...
Private Sub Command1_Click()
' this line will compact the "c:\myDir\db1.mdb" database to "c:\myDir\db2.mdb".
' after this line had been called you will have the original
' uncompacted database in "c:\myDir\db1.mdb"
' and the new compacted database in "c:\myDir\db2.mdb".
DBEngine.CompactDatabase "c:\myDir\db1.mdb", "c:\myDir\db2.mdb"
End Sub
and let us know
JoshT
Nov 22nd, 2000, 07:30 AM
I tried writing code once using Access VBA to issue the Compact and Repair command after a function that deleted records from a table, and I got an error message telling me the c&r command cannot be executed via code...
Josh
paulw
Nov 22nd, 2000, 09:03 AM
Perfectly possible but remember that Compact and Repair operations need exclusive access to the database so have to be done from a separate piece of code. Running it from VB via automation would be fine.
Lafor's code would work but it could not be run from c:\myDir\db1.mdb itself.
Cheers,
P.
JoshT
Nov 22nd, 2000, 01:41 PM
Yeah, I was using this in Access VBA. It is from Access.Application.
RunCommand acCmdCompactDatabase
So in other words, you can compact a DB from Access VBA, only VB.
Josh
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.