To enable the automatic compact, open your Access file and go to Tools \ Options.

 

Select the General Tab and place a checkmark in the box next to “Compact on Close”

  

That’s it! Now each time the database is opened it will automatically compact the data when you close Access.