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
Printable View
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
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
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
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.
Yeah, I was using this in Access VBA. It is from Access.Application.
So in other words, you can compact a DB from Access VBA, only VB.Code:RunCommand acCmdCompactDatabase
Josh