vba ms-access:在数据库打开时做某事
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3094906/
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
ms-access: doing something on database open
提问by l--''''''---------''''''''''''
is it possible to run a sub or function as soon as the user opens an access database file? if so, how?
用户打开访问数据库文件后,是否可以立即运行子程序或函数?如果是这样,如何?
回答by HansUp
Create your function:
创建你的函数:
Public Function DoSomething()
' do stuff '
End Function
Then create a macro with the run code action which calls your DoSomething function. Name the macro autoexec. Then, every time the data base starts up, it will run your autoexec macro.
然后使用调用 DoSomething 函数的运行代码操作创建一个宏。将宏命名为 autoexec。然后,每次数据库启动时,它都会运行您的 autoexec 宏。
Another thing you can do is set a form to open whenever the database starts. You could then call your DoSomething function from a form event (on open, or on load).
您可以做的另一件事是将表单设置为在数据库启动时打开。然后,您可以从表单事件(打开或加载时)调用 DoSomething 函数。
Choose one of those approaches. Either way, if you ever want to start the database withoutDoSomething running, hold down the shift key as the database opens to bypass your automatic startup routine.
选择其中一种方法。无论哪种方式,如果您想在不运行 DoSomething的情况下启动数据库,请在数据库打开时按住 shift 键以绕过自动启动例程。
回答by FloE
You could open a hidden form on start up like in Access 2007 Startup. This is also possible in older Access version.
您可以在启动时打开一个隐藏的表单,就像在Access 2007 Startup 中一样。这在较旧的 Access 版本中也是可能的。
You may use this hidden form for logging or other 'system'-related tasks.
您可以使用此隐藏表单进行日志记录或其他“系统”相关任务。