Hi,
Before writing the Code for Compact, you have to Close the Connection to database. You may also get that error, if the database is "Password" protected.. you will have to pass the Pwd in Compact statement.
Check this :
DBEngine.CompactDatabase "C:\MyDB.mdb" _
,"C:\NewDB.mdb", , , ";pwd=mypwd"
Regards
Veena