"Compact and Repair Database" Command in a Form

M

Michael

I would like to run the "Compact and Repair Database"
command by clicking a command button on a form. I am using
MS Access 2000.

The "DoCmd.RunCommand acCmdCompactDatabase" cannot work
while running a VB code or macro. Also, I can't find the
right parameters to use with "DoCmd.DoMenuItem" for that
command.

I already created a custom toolbar with this command. But
this is the top menu. I would like to have it also in the
main menu, which is a form.

Can it be done?

Thanks,

Michael
 
A

Alp Bekisoglu

Hi Michael,

The following worked for me. Try it in a copy and see if it also works for
you. The code is behind the OnClick event of a commandbutton, in my case the
button name is CompactDB.

Private Sub CompactDB_Click()
On Error GoTo Err_CompactDB_Click

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

Exit_CompactDB_Click:
Exit Sub

Err_CompactDB_Click:
MsgBox Err.Description
Resume Exit_CompactDB_Click

End Sub

Hope this helps,

Alp
 
M

Michael

It works!

Thank you very much!

Michael


-----Original Message-----
Hi Michael,

The following worked for me. Try it in a copy and see if it also works for
you. The code is behind the OnClick event of a commandbutton, in my case the
button name is CompactDB.

Private Sub CompactDB_Click()
On Error GoTo Err_CompactDB_Click

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

Exit_CompactDB_Click:
Exit Sub

Err_CompactDB_Click:
MsgBox Err.Description
Resume Exit_CompactDB_Click

End Sub

Hope this helps,

Alp



.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top