vba 如何强制用户在启动 Access 2007 时处理安全警告?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1852215/
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-11 11:04:26  来源:igfitidea点击:

How to force user to deal with the Security Warning when starting Access 2007?

vbams-access-2007security-warning

提问by Johan

When a user start an Access 2007 database that have macros and vba, a security warning is shown. I want the user to deal with this warning, so if the the content is't enabled, the user should not be able to use the database.

当用户启动具有宏和 vba 的 Access 2007 数据库时,会显示安全警告。我希望用户处理这个警告,所以如果内容没有启用,用户应该不能使用数据库。

Now I use a macro named AutoExec(opens a form that works like a menu), and that macro is run before the user deal with the security warning. But I want to check if the content is enabled and if not I will show a form that inform the user that they should enable the content.

现在我使用一个名为的宏AutoExec(打开一个像菜单一样工作的表单),并且在用户处理安全警告之前运行该宏。但是我想检查内容是否已启用,如果没有,我将显示一个表单,通知用户他们应该启用该内容。

So what I'm actually asking for is how do I do this:

所以我实际上要求的是我如何做到这一点:

  1. If vba and macros is not enabled-> show form "information"
  2. If vba and macros is enabled-> show form "start menu"
  1. 如果未启用vba 和宏-> 显示表单“信息”
  2. 如果启用了vba 和宏-> 显示表单“开始菜单”

回答by Johan

Ok, after a while I have the solution. Thanks for the answers who led me the right way.

好的,过了一会儿我有了解决方案。感谢引导我正确方式的答案。

This articlefrom Microsoft is very helpful.

微软的这篇文章很有帮助。

In the AutoExec-macro, I have two lines:

在 AutoExec 宏中,我有两行:

Line one: Conditions: [CurrentProject].[IsTrusted]=Falseand then I choose witch Form I want to open and in this case it is the "info about security warning form"

第一行:Conditions: [CurrentProject].[IsTrusted]=False然后我选择我想打开的女巫表单,在这种情况下它是“关于安全警告表单的信息”

Line two: Conditions: [CurrentProject].[IsTrusted]=Trueand now open the "start menu form"

第二行:Conditions: [CurrentProject].[IsTrusted]=True现在打开“开始菜单窗体”

And that's all!

就这样!

回答by Rick Mogstad

If the content is disabled, then you cannot check, since your code cannot run....

如果内容被禁用,则您无法检查,因为您的代码无法运行....

回答by Fionnuala

You might like to consider a start-up form ("information"). This will show without macros.

您可能想考虑启动表格(“信息”)。这将在没有宏的情况下显示。

In addition, you can run some start-up code or a macro that closes the information form and opens the main form ("start menu"), if macros are disallowed, this will not run. However, I think you may get an unsightly warning.

此外,您可以运行一些启动代码或关闭信息表单并打开主表单(“开始菜单”)的宏,如果不允许使用宏,则不会运行。但是,我认为您可能会收到难看的警告。

EDIT

编辑

Set the timer interval to say, 100 and add a little code to Information form:

将计时器间隔设置为 100 并在信息表单中添加一些代码:

Private Sub Form_Timer()
   DoCmd.Close acForm, "Information"
   DoCmd.OpenForm "start menu"    
End Sub

回答by Scotch

Just to add my solution -- I was just dealing with this issue.

只是为了添加我的解决方案——我只是在处理这个问题。

By default, in database options have it set to open with form "notEnabled" On this "not enabled" form, have some text, pictures, or what have you that lets the user know that he/she needs to 'enable content'.

默认情况下,在数据库选项中将其设置为以表单“notEnabled”打开。在这个“未启用”表单上,有一些文本、图片或什么让用户知道他/她需要“启用内容”。

In the on loadevent for this form, just put some VBA to open the actual form you want the user to be presented and close the "notEnabled" form.

在此表单的加载事件中,只需放置一些 VBA 即可打开您希望呈现给用户的实际表单并关闭“notEnabled”表单。

This way, if the user opens the database without making it trusted, enabling content, they are stuck on the form that tells them how to do that. As SOON as it's trusted, the on-load event of the form will fire and redirect the user to whichever form you want, with content enabled.

这样,如果用户打开数据库而没有信任它,启用内容,他们就会被困在告诉他们如何做的表单上。只要它被信任,表单的加载事件就会触发并将用户重定向到您想要的任何表单,并启用内容。

If the user opens the database and already has trusted the file, they don't see the form telling them to make it trusted.

如果用户打开数据库并且已经信任该文件,他们将看不到告诉他们使其信任的表单。

回答by David-W-Fenton

You can avoid this by setting the IsTrusted flag to TRUE in your AutoExec macro. See Transitioning Your Existing Access Applications to Access 2007-- search for IsTrusted to get you to the heart of the explanation of how to handle it.

您可以通过在 AutoExec 宏中将 IsTrusted 标志设置为 TRUE 来避免这种情况。请参阅将现有 Access 应用程序转换为 Access 2007-- 搜索 IsTrusted 以了解如何处理它的核心内容。

回答by Jeffrey Longwe

I don't know why people give suggestions that have not been tested yet. My solution is simple:

我不知道为什么人们会给出尚未经过测试的建议。我的解决方案很简单:

If: [CurrentProject].[IsTrusted]=False RunMenuCommand: CloseDatabase

如果:[CurrentProject].[IsTrusted]=False RunMenuCommand: CloseDatabase

Else

别的

If: [CurrentProject].[IsTrusted]=True RunCode: (you run the code or macro you wanted to in the first place here)

如果:[CurrentProject].[IsTrusted]=True RunCode:(您首先在这里运行您想要的代码或宏)

This basically closes the database if the security warnings are coming on. If they are not, it opens just fine. The user that is the admin will need to decrease the macro security levels on the computer of whoever wants to access the database. This macro unlike others will actually run because it agrees with what Access wants.

如果出现安全警告,这基本上会关闭数据库。如果不是,它打开就好了。作为管理员的用户将需要降低想要访问数据库的任何人的计算机上的宏安全级别。与其他宏不同,这个宏实际上会运行,因为它符合 Access 的要求。

You're Welcome!

别客气!