PC Review


Reply
Thread Tools Rate Thread

"Compact and Repair Database" Command in a Form

 
 
Michael
Guest
Posts: n/a
 
      19th Feb 2004
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

 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      19th Feb 2004
You can't compact the current database through code.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(No private e-mails, please)



"Michael" <(E-Mail Removed)> wrote in message
news:131c801c3f730$92bc4a10$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Alp Bekisoglu
Guest
Posts: n/a
 
      20th Feb 2004
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
"Michael" <(E-Mail Removed)> wrote in message
news:131c801c3f730$92bc4a10$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      20th Feb 2004
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
>"Michael" <(E-Mail Removed)> wrote in

message
>news:131c801c3f730$92bc4a10$(E-Mail Removed)...
>> 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
>>

>
>
>.
>

 
Reply With Quote
 
=?Utf-8?B?am1hdGh5cw==?=
Guest
Posts: n/a
 
      10th Mar 2004
This code works fine on condition that it is the only line in the OnClick-event of your pushbutton

If you try to put more commands (like a complete VBA procedure), it won't work
You get a message "You can't compact the open database while running a macro or Visual Basic code. Instead of using a macro or code, on the Tools menu, point to Database Utilities, and then click Compact/Repair Database.

I have no explanation for this strange behaviour, I just found out after a lot of testing, so don't ask me why ..

JMathys
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
after a ftp put command it just says "200 PORT command successful." and hangs forever. What could be wrong? when i test the ftp server using IE in "passive" mode it works fine. but ftp at command line hangs on "200 PORT comma Daniel Microsoft Windows 2000 Security 7 7th Jun 2014 05:24 AM
after a ftp put command it just says "200 PORT command successful." and hangs forever. What could be wrong? when i test the ftp server using IE in "passive" mode it works fine. but ftp at command line hangs on "200 PORT comma Daniel Microsoft Windows 2000 Networking 1 29th Apr 2006 02:42 AM
after a ftp put command it just says "200 PORT command successful." and hangs forever. What could be wrong? when i test the ftp server using IE in "passive" mode it works fine. but ftp at command line hangs on "200 PORT comma Daniel Microsoft Windows 2000 1 29th Apr 2006 02:05 AM
"Compact and Repair Database" Command in a Form Michael Microsoft Access VBA Modules 4 22nd Apr 2004 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.