20

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.

braX
  • 11,506
  • 5
  • 20
  • 33
S..
  • 1,242
  • 8
  • 29
  • 49
  • @Pst, thanks for the edit, will try to frame my question in more efficient manner from next time. – S.. Aug 21 '12 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 Aug 21 '12 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.. Aug 21 '12 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 Aug 21 '12 at 21:51

2 Answers2

28

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).

Phil.Wheeler
  • 16,748
  • 10
  • 99
  • 155
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.

spinjector
  • 3,121
  • 3
  • 26
  • 56