vba 事件在 MS-Access 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1557753/
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
Events not working in MS-Access
提问by a_m0d
The database that I am working on (in MS-Access XP) seems to have become corrupted somehow. It no longer supports any events - clicks, change, update events, nothing seems to work. This is the error that I get:
我正在处理的数据库(在 MS-Access XP 中)似乎以某种方式损坏了。它不再支持任何事件 - 单击、更改、更新事件,似乎没有任何效果。这是我得到的错误:
The expression On Change you entered as the event property setting produced the following error: Object or class does not support the set of events.
您作为事件属性设置输入的表达式 On Change 产生以下错误:对象或类不支持事件集。
What can I do to make events start working again? I have tried Tools->Database Utilities->Compact and Repair Database..., but it didn't help at all. Also, it hasn't been like this the whole time - events were originally working, but now nothing works, not even the auto-generated command buttons.
我该怎么做才能让事件重新开始工作?我试过Tools->Database Utilities->Compact and Repair Database...,但它根本没有帮助。此外,它一直都不是这样 - 事件最初有效,但现在没有任何作用,甚至自动生成的命令按钮也无效。
回答by Tony Toews
Compact and repair generally won't solve problems that happens in objects other than tables and indexes. Importing usually fixes those but maybe try a decompile and then an import. Decompile or how to reduce Microsoft Access MDB/MDE size and decrease start-up times
压缩和修复通常不会解决表和索引以外的对象中发生的问题。导入通常会修复这些问题,但可能会尝试反编译然后导入。 反编译或如何减少 Microsoft Access MDB/MDE 大小并减少启动时间
I encountered the same problem once and documented my trouble shooting steps here. The expression On Click you entered ...
我曾经遇到过同样的问题,并在此处记录了我的故障排除步骤。 您输入的表达式 On Click ...
Also see Corrupt Objects within a Corrupt Microsoft Access MDB
另请参阅损坏的 Microsoft Access MDB 中的损坏对象
Long discussion summarized.
长时间的讨论总结。
One page that might have a solution that might help is Errors using multiple versions of Access under Vista/Windows 7This is basically a permissions problem into the registry.
一个可能有帮助的解决方案的页面是在 Vista/Windows 7 下使用多个版本的 Access 的错误这基本上是注册表的权限问题。
Another suggestion is to to repair the Office 2003 installation in control panel. A2003 then reverts to using Version 11 of the library, but only until A2007 is used again, then the problem reappears.
另一个建议是修复控制面板中的Office 2003 安装。A2003 然后恢复使用库的版本 11,但直到再次使用 A2007,然后问题再次出现。
The original poster stated "Okay, after a few restarts, it seems that removing the 2007 runtime did fix the problem for me. "
原始海报说“好吧,经过几次重新启动后,似乎删除 2007 运行时确实为我解决了问题。”
回答by David-W-Fenton
Tony alluded to this in his long string of comments, but this sounds exactly like the dueling Access registration problem. I hadn't used A2007 until recently (I had the runtime installed to test if a database developed in A2003 could be deployed under it -- it could -- but hadn't used it since that testing was completely), and when I run A2007 after I've been using A2003, it has to reconfigure itself. The other day, something went wrong during the A2003 reconfiguration (after having last run A2007) and I got errors similar to yours. Running A2007 (to re-register everything as A2007) and then running A2003 (to re-register everything as A2003) fixed the problem.
托尼在他的一长串评论中提到了这一点,但这听起来就像决斗的访问注册问题。直到最近我才使用 A2007(我安装了运行时来测试在 A2003 中开发的数据库是否可以部署在它之下——它可以——但是自从测试完成后没有使用它),当我运行时A2007 在我使用 A2003 之后,它必须重新配置自己。前几天,在 A2003 重新配置期间(在上次运行 A2007 之后)出现问题,我遇到了与您类似的错误。运行 A2007(将所有内容重新注册为 A2007)然后运行 A2003(将所有内容重新注册为 A2003)解决了该问题。
The key is that when the re-registration fails, Access doesn't necessarily know it the next time it runs, so you end up running in an environment that is partly registered for A2003 and partly for A2007. The way to restore it is to run the other version of Access. That is, if A2003 is launching without the reconfiguration notice, then close it down and run A2007 so it reconfigures itself and re-registers itself as the real Access. Then when you run A2003 next, it will re-register itself as the authoritative version of Access and your A2003 app should have all of its references in proper shape.
关键是,当重新注册失败时,Access 不一定会在下次运行时知道它,因此您最终会在部分注册为 A2003 部分注册为 A2007 的环境中运行。恢复它的方法是运行其他版本的 Access。也就是说,如果 A2003 在没有重新配置通知的情况下启动,则关闭它并运行 A2007,以便它重新配置自己并将自己重新注册为真正的 Access。然后,当您接下来运行 A2003 时,它会将自己重新注册为 Access 的权威版本,并且您的 A2003 应用程序的所有引用都应具有正确的形状。
Yes, this is very annoying.
是的,这很烦人。
And time-consuming.
而且很费时间。
I don't know why MS seems to think this is something that doesn't need to be fixed. While I know they don't give a rat's ass about developers who need to run A2003 and A2007 side by side, there are plenty of end users who might have an A2007 runtime app installed but also have A2003 installed as part of their base Office installation.
我不知道为什么 MS 似乎认为这是不需要修复的东西。虽然我知道他们并没有对需要同时运行 A2003 和 A2007 的开发人员表示怀疑,但有很多最终用户可能安装了 A2007 运行时应用程序,但也安装了 A2003 作为其基本 Office 安装的一部分.
This has been going on forever, so I doubt it will ever be fixed.
这一直在发生,所以我怀疑它永远不会被修复。
回答by Ashwin
I have encountered the same problems many times in Access 2013. From a page on MS web site, I found the answer which solved my problem. I am sharing it here.
我在 Access 2013 中多次遇到同样的问题。从 MS 网站上的一个页面中,我找到了解决我问题的答案。我在这里分享。
- I copied the code safely somewhere else outside Access, in the Notepad++.
- Then I deleted entire vent Procedure, with its code, which was not firing.
- Created fresh Event procedure, and restored the code from Notepad++ to the newly created Event Procedure.
- The event earlier not firing started without any glitch. The issue got solved.
- 我将代码安全地复制到 Access 之外的其他地方,在 Notepad++ 中。
- 然后我删除了整个vent Procedure 及其代码,但没有触发。
- 创建新的事件过程,并将代码从 Notepad++ 恢复到新创建的事件过程。
- 之前没有触发的事件开始时没有任何故障。问题得到了解决。
I don't know why the problem appears. This problem has come up many times and every time it is resolved with the same solution.
我不知道为什么会出现这个问题。这个问题出现了很多次,每次都用相同的解决方案解决。
Try it.
尝试一下。
回答by Shawne Botha
I had a similar problem. When it started I created a new version of the code by copying the database. This did not help. However, deleting the form from the new database and importing it from the original solved the issue. I did not receive any warnings of corrupted code or other. It simply just worked without any changes to the VBA etc. Bit weird all in all
我有一个类似的问题。当它开始时,我通过复制数据库创建了一个新版本的代码。这没有帮助。但是,从新数据库中删除表单并从原始数据库中导入它解决了这个问题。我没有收到任何有关损坏代码或其他的警告。它只是在没有对 VBA 等进行任何更改的情况下工作。总之有点奇怪
回答by Carl Brady
I compacted the database (Access 2010) into a new one. No joy. Deleted the form that was not working and imported it from the old database. No joy. Recompiled. JOY!Not sure why it quit and why it now works. I suspect a problem with a large amount of text in a linked text box on the form.
我将数据库(Access 2010)压缩成一个新的。没有喜悦。删除了无效的表单并将其从旧数据库中导入。没有喜悦。重新编译。喜悦!不知道为什么它退出以及为什么它现在有效。我怀疑表单上链接文本框中的大量文本有问题。
回答by Kevin Ross
You decompile the database by adding the flag /decompile to the start-up options i.e.
您可以通过在启动选项中添加标志 /decompile 来反编译数据库,即
msaccess.exe “C:\my_folder\mydb.mdb” /decompile
msaccess.exe “C:\my_folder\mydb.mdb”/反编译
I find that solves most of my problems. If not then another one is to re-secure the database by running the security wizard. This basically makes a new db and imports all the objects for you
我发现这解决了我的大部分问题。如果没有,那么另一个是通过运行安全向导来重新保护数据库。这基本上创建了一个新的数据库并为您导入所有对象
回答by Raj More
Try to decompile and recompile the database.
尝试反编译并重新编译数据库。
If that does not work, I usually create a new database and import everything from this one to the new one. If something is corrupted, I will encounter issues at that time and be able to fix it.
如果这不起作用,我通常会创建一个新数据库并将所有内容从这个数据库导入到新数据库。如果某些东西损坏了,我会在那个时候遇到问题并且能够修复它。
回答by Larry Lustig
Can you see the code in your code modules? If so, cut and paste it somewhere safe. Then flip the HasModule setting for each form to false, repair the database, and restore the code to newly created code modules.
你能在你的代码模块中看到代码吗?如果是这样,请将其剪切并粘贴到安全的地方。然后将每个表单的HasModule设置翻转为false,修复数据库,将代码恢复到新创建的代码模块中。