Automate compact and repair

Automate compact and repair

am 25.12.2007 22:50:36 von Johnie

In an Access 2000 database in Access 2003 (Dutch) I have the following code:

Option Compare Database
Option Explicit

Public Sub CompactDB()
CommandBars("Menu Bar"). _
Controls("Tools"). _
Controls("Database utilities"). _
Controls("Compact and repair database..."). _
accDoDefaultAction
End Sub

Private Sub test2_Click()
CompactDB
End Sub

Following references are checked:
- Visual Basic for Applications
- Microsoft Access 11.0 Object Library

When I press the test2 button I keep getting the error message:
Invalid procedure call or invalid argument.

What am I doing wrong?
Thanks,
John