# Database Discussions > Microsoft Access >  Closing front end by vba to compact a backend Access database by vba

## compton

Closing front end by vba to compact a backend Access database by vba

I wish to by vba close the front end of an Access data base so it is not running when a compact backend database is called from vba by a third utility database.

I have three databases.
The front end database. DbFront 
The back end database. DbBackend
A utility  database. DbUtility where dbUtility opens automatically by an autoexec macro to a form with a button that when click compacts DbBackend

All this works fine if I physically close DbFront navigate to DbUtility and click the compact button.
(I have the code installed on a button on a form in the Utility database that actually compacts the back end. Working fine.)

However, I would prefer to call the compact back end instruction from within the front end but it seems that once the form on a Utility database opens (in modal pop up) focus is lost with the front end and the code to close (quit) the front end does not complete. Leaving both the front end and utility databases visible with the focus on the utility form.

I can see the logic if is not possible for the front end code to complete when the utility opens.

So, I have tried a different approach where a user would locate and open the Utility database and click the compact button. I wish code to be added to the compact button that checks if the front end is open and either closes it or issues a message that it is open and quits (Utility database quits if front end is open.

This is where my lack of coding knowledge has stumped me. I will be grateful if anyone can point me in the right direction to vba code that may fulfil what I am trying to achieve.

Thanks

----------


## apr pillai

Take a look at this Article: Repairing Compacting Database with VBA; you will be better informed on this subject.

----------

