DBEngine.CompactDatabase Compile Error: Argument not Optional

  • Thread starter Thread starter M Skabialka
  • Start date Start date
M

M Skabialka

What is the correct format of the function to compact a database in Access
2007? I run some code which deletes then adds a few thousand records to the
database back end, which bloats it to about 65 MB, so I want to add a step
at the end to compact it back down to about 15 MB.
I am trying to compile this code, but .CompactDatabase is highlighted and
the error message is "Compile Error: Argument not Optional"
I have tried these variations:
DBEngine.CompactDatabase ("C:\Documents and Settings\me\My Documents\Test
compact database.mdb")
DBEngine.CompactDatabase "C:\Documents and Settings\me\My Documents\Test
compact database.mdb"
Do I have to create a new database when I compact one - is that the problem?
If I compact manually I don't have to specify a new name.
Mich
 
M Skabialka said:
What is the correct format of the function to compact a database in Access
2007? I run some code which deletes then adds a few thousand records to
the database back end, which bloats it to about 65 MB, so I want to add a
step at the end to compact it back down to about 15 MB.
I am trying to compile this code, but .CompactDatabase is highlighted and
the error message is "Compile Error: Argument not Optional"
I have tried these variations:
DBEngine.CompactDatabase ("C:\Documents and Settings\me\My Documents\Test
compact database.mdb")
DBEngine.CompactDatabase "C:\Documents and Settings\me\My Documents\Test
compact database.mdb"
Do I have to create a new database when I compact one - is that the
problem? If I compact manually I don't have to specify a new name.
Mich


Yes, the SrcName and DstName arguments are both required arguments. Here's a
link to the on-line help topic ...

http://office.microsoft.com/client/...ESS.DEV&lcid=2057&QueryID=K3NDdHcOi0&respos=1

When you compact using the Access UI, Access first compacts to a temporary
file, and then deletes the old file and renames the temporary file with the
same name as the old file, only if no error occurred. I'd advise doing the
same when compacting programmatically.
 
Back
Top