在 Access 2007 中执行任何 VBA 代码时出现“找不到文件”

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

"File not found" at the execution of any VBA code in Access 2007

vbams-access

提问by dan

I'm working on a big Access 2003 project with Microsoft Access 2007-. Recently, some users have started to experience problems with the buttons in my forms. For example, without any specific reason, clicking on a button or trying to execute any code will return the error:

我正在使用 Microsoft Access 2007- 进行一个大型 Access 2003 项目。最近,一些用户开始遇到我表单中按钮的问题。例如,在没有任何特定原因的情况下,单击按钮或尝试执行任何代码都会返回错误:

File not found

文件未找到

There is no way to go into debug mode. When this happens the only thing to do is to restart the database. I tried adding the Stopcommand at the beginning of the executed block to try debugging it, but no code is executed at all. It's like a compilation error but it's only happening 5-10% of the time, which is really weird.

无法进入调试模式。发生这种情况时,唯一要做的就是重新启动数据库。我尝试Stop在执行块的开头添加命令来尝试调试它,但根本没有执行任何代码。这就像一个编译错误,但它只发生 5-10% 的时间,这真的很奇怪。

After some research, I found other people are having the same problem, for example thisand thislink. There are other examples too, with no real solutions yet.

经过一番研究,我发现其他人也有同样的问题,例如这个这个链接。还有其他例子,目前还没有真正的解决方案。

My database can be okay for a week and then the problem starts to happen again. Half the time and users can't do much; they need to restart the database once or twice to get it back working, and after a few minutes the error might happen again.

我的数据库可以正常使用一周,然后问题又开始发生。一半的时间和用户无能为力;他们需要重新启动数据库一两次才能让它恢复工作,几分钟后错误可能会再次发生。

Because this is Access 2007 and there are a lot of people experiencing this bug, I can't believe it isn't more documented.

因为这是 Access 2007 并且有很多人遇到这个错误,我不敢相信它没有更多的记录。

What's the problem? Is the database somehow partially corrupted? What should I do? This is really annoying.

有什么问题?数据库是否以某种方式部分损坏?我该怎么办?这真的很烦人。

采纳答案by Gord Thompson

If I was in this situation one of the first things I would try would be to do a complete decompile+compact+recompile operation on the front-end database file, and then distribute that updated front-end out to the users to see if that improves things.

如果我遇到这种情况,我会尝试的第一件事就是对前端数据库文件进行完整的反编译+压缩+重新编译操作,然后将更新后的前端分发给用户,看看是否改善事情。

Detailed instructions on the decompile+compact+recompile steps are available here. Note:Be sure to read David W. Fenton's additional recommendations in his answer.

此处提供有关反编译+压缩+重新编译步骤的详细说明。注意:请务必阅读 David W. Fenton 在他的回答中的其他建议。

回答by Dennis Flory

I had just experienced this for the first time. I had been making extensive coding changes in a form, and was required to reboot my PC without finishing debugging the code. When I opened the app, I immediately got the "file not found" message (it auto-starts a different form).

我刚刚第一次体验到这种情况。我一直在对表单进行大量的编码更改,并且需要在未完成代码调试的情况下重新启动我的 PC。当我打开应用程序时,我立即收到“找不到文件”消息(它会自动启动不同的表单)。

On a whim, I went to the form in question and commented out that entire module's code and the problem went away. After I went back in and uncommented that code, everything still worked as normal. I was able to continue debugging that code and lived for the rest of the day happily.

一时兴起,我转到有问题的表单并注释掉整个模块的代码,问题就消失了。在我返回并取消注释该代码后,一切仍然正常。我能够继续调试该代码并愉快地度过了余下的一天。

回答by www.MSOffice-deluxe.com

though this thread is over a year old I would like to share another very helpful observation.

虽然这个线程已经一年多了,但我想分享另一个非常有用的观察。

This error "File not found:" may be caused by differing save behavior of Office versions and may not have anything to do with your code! In case of this error, try to open and save your troubled file in another Office version and it may work fine back in your main Office version.

此错误“找不到文件:”可能是由 Office 版本的不同保存行为引起的,可能与您的代码无关!如果出现此错误,请尝试在另一个 Office 版本中打开并保存您的问题文件,它可能会在您的主 Office 版本中正常工作。

Details: Though programming VBA for years now, I had never had an unsolicited "File not found:" error. Weird also that the error message does not give a file name for the file not found. (Reminded me of another nasty error VBA sometimes shows on startup for no obious reason and erratically.) Luckily this error started after my first edits in PowerPoint 2010 after having tested the file in PowerPoint 2016. The error occurred when opening the .pptm but I had no startup procedure involving a file. So I've got the idea of some file in the .pptm zip archive not being found. Started to do a quick search on the internet and found only "shooting in the dark" suggestions. As I could start PowerPoint 2013 more easily (virtual machine) than PowerPoint 2016 (different Windows 10 boot partition), I tried to open the troubled file in PowerPoint 2013 and had no problems. I compiled the VBA project to check for error. Nothing. And save the file. After this re-saving in PowerPoint 2013, the file seems to work fine again in PowerPoint 2010 und did not show any problems after the first few edits, saves and re-opening. This being said, I wonder if PowerPoint 2016 saving is peculiar and if I can replicate/if I will run into the error again if saving the file again in PowerPoint 2016 and returning to PowerPoint 2010. (I'll make a note of this thread to add new insights once I worked with this file again in PowerPoint 2016.)

详细信息:尽管多年来一直在为 VBA 编程,但我从未遇到过未经请求的“找不到文件:”错误。奇怪的是,错误消息没有为找不到的文件提供文件名。(让我想起了另一个令人讨厌的错误 VBA 有时会在启动时显示,因为没有明显的原因而且不规律。)幸运的是,在 PowerPoint 2016 中测试了文件后,我在 PowerPoint 2010 中的第一次编辑后开始出现此错误。打开 .pptm 时发生错误,但我没有涉及文件的启动程序。所以我知道 .pptm zip 存档中的某些文件没有被找到。开始在互联网上进行快速搜索,发现只有“在黑暗中拍摄”的建议。因为我可以比 PowerPoint 2016(不同的 Windows 10 启动分区)更容易地启动 PowerPoint 2013(虚拟机),我尝试在 PowerPoint 2013 中打开有问题的文件,没有任何问题。我编译了 VBA 项目来检查错误。没有。并保存文件。在 PowerPoint 2013 中重新保存后,该文件在 PowerPoint 2010 中似乎再次正常工作,并且在前几次编辑、保存和重新打开后没有显示任何问题。话虽如此,我想知道 PowerPoint 2016 的保存是否很奇特,我是否可以复制/如果在 PowerPoint 2016 中再次保存文件并返回到 PowerPoint 2010,我是否会再次遇到错误。(我会记下这个线程在 PowerPoint 2016 中再次使用此文件后添加新见解。)该文件似乎在 PowerPoint 2010 中再次正常工作,并且在前几次编辑、保存和重新打开后没有显示任何问题。话虽如此,我想知道 PowerPoint 2016 的保存是否很奇特,我是否可以复制/如果在 PowerPoint 2016 中再次保存文件并返回到 PowerPoint 2010,我是否会再次遇到错误。(我会记下这个线程在 PowerPoint 2016 中再次使用此文件后添加新见解。)该文件似乎在 PowerPoint 2010 中再次正常工作,并且在前几次编辑、保存和重新打开后没有显示任何问题。话虽如此,我想知道 PowerPoint 2016 的保存是否很奇特,我是否可以复制/如果在 PowerPoint 2016 中再次保存文件并返回到 PowerPoint 2010,我是否会再次遇到错误。(我会记下这个线程在 PowerPoint 2016 中再次使用此文件后添加新见解。)

Hope this observation may spare many unnecessary un-/re-installations of Office and other desperate attempts.

希望这一观察可以避免许多不必要的卸载/重新安装 Office 和其他绝望的尝试。

Cheers!

干杯!

回答by Buyani

A similar thing has just happened to me a couple of times with one of my .mdb front ends running in Access 2013, after the August 2019 update to Windows 10.

在 2019 年 8 月更新到 Windows 10 之后,类似的事情发生在我身上几次,我的一个 .mdb 前端在 Access 2013 中运行。

My DBs too have been through several versions of Access. On opening the database it says 'File Not Found' and throws up a public module (not one on which I have been working extensively recently), without opening the Autoexec (Switchboard) form. 'Debug, Compile' is possible and doesn't suggest any problem.

我的数据库也经历了多个版本的 Access。打开数据库时,它说“找不到文件”并抛出一个公共模块(不是我最近一直在广泛工作的模块),而没有打开 Autoexec (Switchboard) 表单。“调试,编译”是可能的,并且没有任何问题。

For me too, typing one space (or blank line or other character) anywhere in the code, and then deleting it, and saving, closing and re-opening seemed to provide a workaround, and all has been well for the last few days (I am the only user at present).

对我来说也是如此,在代码中的任意位置输入一个空格(或空行或其他字符),然后将其删除,然后保存、关闭和重新打开似乎提供了一种解决方法,而且最近几天一切都很好(我是目前唯一的用户)。

There is no one obvious module involved, although I will probably suspect the form module I have been working on most recently if the problem persists in a troublesome way.

没有涉及任何明显的模块,尽管如果问题以一种麻烦的方式持续存在,我可能会怀疑我最近一直在处理的表单模块。

Now, a few days later I have de-compiled, compacted and re-compiled the database, halving its size, so maybe that will have done the trick. I hope so.

现在,几天后,我对数据库进行了反编译、压缩和重新编译,将其大小减半,所以也许这可以解决问题。但愿如此。

回答by SmrtGrunt quit because Monica

I had this problem as well, and compact/repair did not fix it. In my case I had an old VBA module that was no longer used, and which referenced an object class that no longer existed. Removing the non-compiling code fixed the issue for me.

我也有这个问题,并且压缩/修复没有解决它。在我的例子中,我有一个不再使用的旧 VBA 模块,它引用了一个不再存在的对象类。删除非编译代码为我解决了这个问题。

回答by Christopher Fisher

I have had this problem for many years now in access 2010. Always in the Autoexec form that opens on msaccess startup. I tried creating a very simple form that calls the original more complex form. To my surprise the more problem moved the the new simple form. By trial and error, I found that just editing the new simple Autoexec form the problem would go away, but turn up randomly months later ALWAYS after I had made programming changes elsewhere. Sometimes instead of the file not found error, I get just get a crash out of access - but the solution is the same procedure - make a small edit to the autoexec file (just add new blank line will do). My project has come through many versions of access (2000 -> 2010). If there was some way to automate the editing of my autoexec form, then restarting access - this would serve as a workaround. I have not found any way as yet.

我在 access 2010 中遇到这个问题很多年了。总是在 msaccess 启动时打开的 Autoexec 表单中。我尝试创建一个非常简单的表单,它调用原始的更复杂的表单。令我惊讶的是,更多的问题移动了新的简单表格。通过反复试验,我发现只需编辑新的简单 Autoexec 表单,问题就会消失,但在我对其他地方的编程进行更改后,几个月后总是随机出现。有时,而不是文件未找到错误,我只是在访问中崩溃 - 但解决方案是相同的过程 - 对 autoexec 文件进行小的编辑(只需添加新的空行即可)。我的项目经历了许多版本的访问(2000 -> 2010)。如果有某种方法可以自动编辑我的 autoexec 表单,然后重新启动访问 - 这将作为一种解决方法。

回答by LeftyMaus

Had the same problem. I stumbled on the fix by accident. For whatever reason, simply adding an on-click Event Procedure made everything better.

有同样的问题。我偶然发现了修复程序。无论出于何种原因,只需添加一个单击事件过程即可使一切变得更好。

  • Open the form in design mode
  • Select an object on the form
  • Press F4 to display the object's properties
  • object properties
  • Event > On Click > dropdown > click [Event Procedure]
  • Then click the three dots, which will create a new event, and launch the Visual Basic editor. This will also add default code into the Visual Basic editor
  • Make no other changes
  • Save and close changes to the form
  • Restart the database
  • 在设计模式下打开表单
  • 在表单上选择一个对象
  • 按 F4 显示对象的属性
  • 对象属性
  • 事件>点击>下拉>点击[事件程序]
  • 然后单击三个点,这将创建一个新事件,并启动 Visual Basic 编辑器。这也会将默认代码添加到 Visual Basic 编辑器中
  • 不做其他更改
  • 保存并关闭对表单的更改
  • 重启数据库

For what its worth, as I was wrestling with this issue, the error resolved itself in other ways, but none of them were repeatable.

对于它的价值,当我正在解决这个问题时,错误以其他方式自行解决,但没有一个是可重复的。

回答by Hugh Seagraves

I just had this problem. In my case, I think the issue is having a blank VBA module. I was moving procedures from one module to another and ended-up with a blank module. I couldn't delete the module manually and every time I tried to create a procedure to delete blank modules, I received the "File not found" error and the procedure I had just created was blanked out. I ended-up reverting to a backup.

我刚遇到这个问题。就我而言,我认为问题在于有一个空白的 VBA 模块。我正在将程序从一个模块移动到另一个模块,最终得到一个空白模块。我无法手动删除模块,每次尝试创建删除空白模块的过程时,我都会收到“找不到文件”错误,并且我刚刚创建的过程被清除。我最终恢复到备份。

回答by Steve M.

The issue is just your references. One of the files for your references has been moved/deleted/updated. Remove and re-add your references to figure out which one.

问题只是你的参考。您的参考文件之一已被移动/删除/更新。删除并重新添加您的参考以找出哪一个。

回答by enderland

I had a problem similar to this. A blank "File Not Found" error.

我遇到了类似的问题。一个空白的“找不到文件”错误。

I turned off AutoCorrect and after clicking through several prompts/warnings which had me concerned, I then reopened the database and the error went away.

我关闭了自动更正,在点击了几个让我担心的提示/警告后,我重新打开了数据库,错误消失了。

When reopening the database the problem was resolved.

重新打开数据库时,问题已解决。

I suspect this will fix many "File not found" errors which are probably related to the temporary link table losing a reference for whatever reason.

我怀疑这将修复许多“找不到文件”错误,这些错误可能与临时链接表因任何原因丢失引用有关。