I don't know about how to do it in code, but there is this option which may be of interest to you:
Compact and repair an Access file automatically every time you close it
Compacting does not occur if you close a shared Access database(multiuser (shared) database: A database that permits more than one user to access and modify the same set of data at the same time.) while another user has it open.
[ol][li]Open the Access database or Access project that you want Microsoft Access to compact automatically.[/li]
[li]On the Tools menu, click Options.[/li]
[li]Click the General tab.[/li]
[li]Select the Compact on Close check box.[/li]
[/ol]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.