MS Access VBA 是否有“关闭时”事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12063404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 13:50:22  来源:igfitidea点击:

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

vbams-access-2007access-vba

提问by S..

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.

我知道我们可以在 Excel VBA 中使用 Auto_Close 函数在关闭书籍之前强制事件。MS Access VBA 中是否有类似的功能?如果是这样,一个例子将不胜感激。

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

如果您需要更多信息,请告诉我。谢谢你。

回答by Phil.Wheeler

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 unloadevent for that form (which will always be fired before Access completely closes).

不,MS Access 没有应用程序退出或关闭事件。常见的方法似乎是始终打开一个隐藏的表单,然后在该unload表单的事件中处理应用程序的任何逻辑(总是在 Access 完全关闭之前触发)。

回答by spinjector

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.

一种可能性是创建 Microsoft Access 共享 COM 加载项。但是,这需要安装 Visual Studio 以及一些中级编程技能。COM 加载项具有启动和关闭事件处理程序,它们可用于在发生这些事件时执行某些操作。