Is there an "On Close" event for MS Access VBA?
Asked Answered
C

2

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.

Camouflage answered 21/8, 2012 at 21:34 Comment(4)
@Pst, thanks for the edit, will try to frame my question in more efficient manner from next time.Camouflage
No, there is not, but you can fake something up with a hidden form. It all depends on what you are doing.Boarfish
@ 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.Camouflage
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.Boarfish
T
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).

Tolbooth answered 21/8, 2012 at 21:51 Comment(1)
Private Sub Form_Unload(Cancel As Integer) ... End SubPhlebotomize
C
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.

Cenesthesia answered 3/1, 2020 at 17:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.