How to compact the current MS Access database from VBA function
3
votes
4
answers
28814
views
I want to be able to run the 'compact and repair' process from within a VBA module in the database.
I have a batch process that I run occasionally, it drops a few old tables, re-imports them from other databases, renames a couple of fields, does a few updates and makes a few other minor changes. The process isn't rocket science, but there are several steps so it really does needs to be automated.
The problem is that a couple of the steps (the UPDATEs) temporarily increase the size of the database which can cause problems with subsequent imports.
If I do the process manually (including compacting) then everything works fine and I end up with a 800MByte database. If I use my automated VBA script (without compacting) then it crashes halfway through when the database busts the 2Gbyte limit.
I've found several threads on this subject, but they're all three of four years old (or more) and the methods they describe don't seem to work anymore.
Are they're any solutions that work with Office 365 (version 1720)?
The 'auto compact' causes the database to compact on closing, it does NOT allow the compaction of the database to be added between steps.
I've tried this:
Public Sub CompactDb2()
Dim control As Office.CommandBarControl
Set control = CommandBars.FindControl(Id:=2071)
control.accDoDefaultAction
End Sub
And this:
Public Sub CompactDb1()
CommandBars("Menu Bar").Controls("Tools").Controls("Database utilities"). _
Controls("Compact and repair database...").accDoDefaultAction
End Sub
And this....
Public Sub CompactDb3()
Application.SetOption "Auto compact", True
End Sub
Amongst other
Asked by ConanTheGerbil
(1303 rep)
Dec 14, 2017, 02:03 PM
Last activity: Jul 24, 2024, 11:50 AM
Last activity: Jul 24, 2024, 11:50 AM