21

Am trying to perform some specific actions, before closing the access database (whenever the database is closed by the user).

I know we can use Auto_Close function in Excel VBA to force events before closing the book. Is there a similar function in MS Access VBA? If so, an example would be appreciated.

Please let me know if you need more information. Thank you.

4
  • @Pst, thanks for the edit, will try to frame my question in more efficient manner from next time.
    – S..
    Commented Aug 21, 2012 at 21:43
  • No, there is not, but you can fake something up with a hidden form. It all depends on what you are doing.
    – Fionnuala
    Commented Aug 21, 2012 at 21:44
  • @ Remou, Basically i want to compact the database each time i close the database. I know we could use the "Compact on Close" from the access options, but i want to take input from the user using the VBA Yes/NO option and then compact the database. Beacuse the user may be anoyed if it compacts the database all the time, as some times he may have closed it accidently and takes a lot of time.
    – S..
    Commented Aug 21, 2012 at 21:49
  • 2
    Compact on close is not a good idea. It is nearly always a good idea to back-up before you compact. I suggest you add an event to task scheduler. Otherwise, add it to the user's menu options. BTW it sounds as if your database is single user and not split, if that is not the case, things get more complicated.
    – Fionnuala
    Commented Aug 21, 2012 at 21:51

2 Answers 2

29

No, there isn't an application quit or close event for MS Access. The common approach seems to be having a hidden form open at all times and then handling any logic for the application within the unload event for that form (which will always be fired before Access completely closes).

1
  • 1
    Private Sub Form_Unload(Cancel As Integer) ... End Sub
    – Aba
    Commented Mar 3, 2015 at 15:35
0

One possibility is to create a Microsoft Access Shared COM Add-In. However, this would require an installation of Visual Studio, as well as some mid-level programming skills. COM add-ins have startup & shutdown event handlers, and these could be used to perform some actions when these events occur.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.