I have a large MS Access application with a lot of computations in VBA code. When I run it it eventually crashes due to excessive file size. There are a lot of intermediate tables and queries created and subsequently deleted, but Access does not reclaim the space. I have diligently closed all intermediate record sets and set all temporary objects to nothing, but nothing helps. The only way I can get my code to run is to run part of it, stop and repair/compress the file then restart the code.
Isn't there a better way?
Thanks
The database can grow in use, even if you don't save a lot more data. If you use temporary or work tables in the database, then delete their contents after you're done, Access won't be able to recover that space until you compact the database.
Open MS Access database file. Go to the Database Tools Menu, click on Compact and Repair Database. (This may take some time, which depends on the database file size). As you add, update the data, and change its design, a database file becomes larger.
General. 2 gigabytes, minus the space needed for system objects. Note: You can work around this size limitation by linking to tables in other Access databases. You can link to tables in multiple database files, each of which can be as large as 2GB.
Lots of adding and deleting records is one cause of database bloat. If this is your development db, then database bloat is unavoidable as you repeatedly compile and save your vba project; the bloat may be far less pronounced in end-user databases.
You should be able to run the compact function from within your VBA code.
I had the below snippet bookmarked from a long time ago when I was doing access work.
Public Sub CompactDB()
CommandBars("Menu Bar").Controls("Tools").Controls("Database utilities").Controls("Compact and repair database...").accDoDefaultAction
End Sub
You can put that in your code to get around it.
NOTE: you might also consider growing to a larger db system if you are having these types of scaling issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With