Compacting DB error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to enable users to compact a database after importing a large file.
Below is the code when the user clicks on a Compact Database button. I am
now getting a message that says:

"You can't compact the open database, while running a macro or Visual Basic
code. Instead of using the macro or code, on the Tools menu, point ot
Database
Utilities, and then click Compact/Repair Database."

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Compact_Database_Click()

CompactDB

End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub CompactDB()

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

MsgString = "The database has been compacted for better performance."
MsgBox MsgString, , "Database Compacted"

End Sub

Any suggestions or comments to alleviate this problem would be greatly
appreciated. Thanks for all of the help with this project.
 
Move the message box to the beginning of your code
MsgString = "The database will be compacted for better performance."
MsgBox MsgString, , "Database Compacted"

run the message box prior to compacting.
 
How do you transform the code if you use a front-end and want to compact the
back-end ???
 
Back
Top