如何摆脱不支持表单删除的持久 VBA 表单对象?

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

How can I get rid of a persistent VBA Form Object that won't honor the form deletion?

formsvbaobjectms-accessaccess-vba

提问by Tim Visher

I have an MS Access 2003 database that I'm using to develop a basic little inventory app. I have added some extraneous forms along the way and I wanted to get them out of the DB. I deleted most of them just fine but one of them appears to have left behind its VBA Object. All that's in the object is Option Compare Database. Now whenever I try to work with the database, I get the following error:

我有一个 MS Access 2003 数据库,我用它来开发一个基本的小库存应用程序。我在此过程中添加了一些无关的表单,我想将它们从数据库中删除。我删除了其中的大部分就好了,但其中一个似乎已经留下了它的 VBA 对象。对象中的所有内容都是Option Compare Database. 现在,每当我尝试使用数据库时,都会出现以下错误:

The form name 'Transaction1' is misspelled or refers to a form that doesn't exist.

If the invalid form name is a macro, ...

Truncated for typings sake.

为了打字而被截断。

Yes, I agree, the form doesn't exist. What confuses me so much is that all of the other forms, when I deleted them, also destroyed their VBA object as well. This one, no matter what, seems to like to stick around and I have no idea how to get rid of it.

是的,我同意,该表格不存在。让我如此困惑的是所有其他表单,当我删除它们时,也破坏了它们的 VBA 对象。无论如何,这个人似乎喜欢留下来,我不知道如何摆脱它。

How do I get rid of it?

我该如何摆脱它?

Things I've tried:

我尝试过的事情:

  • Compact and Repair and the DB
  • Create a new form named what it's expecting, verify that it gets rid of the problem, and then delete that form.
  • 压缩和修复和数据库
  • 创建一个名为 what it's expecting 的新表单,验证它是否解决了问题,然后删除该表单。

回答by DJ.

You can try the /decompile switch

你可以试试 /decompile 开关

  • Make a backup of your mdb
  • Open your mdb (hold the SHIFT key down to stop any code from running) via a short cut: msaccess.exe database.mdb /decompile
  • Open a module and compile your app
  • Save and close Access
  • Open again (SHIFT again) without decompile
  • Compact and repair database
  • close Access
  • 备份您的 mdb
  • 通过快捷方式打开您的 mdb(按住 SHIFT 键以停止运行任何代码):msaccess.exe database.mdb /decompile
  • 打开一个模块并编译您的应用程序
  • 保存并关闭访问
  • 再次打开(再次 SHIFT)无需反编译
  • 压缩和修复数据库
  • 关闭访问

回答by Robbo

I had similar problem. I found I had named the missing form in the STARTUP menu as the default form to open when starting Access. I opened Tools>Startup and deleted the missing forms name from the "Display/Form/Page" field of the Startup. My problem solved.

我有类似的问题。我发现我已将 STARTUP 菜单中缺少的表单命名为启动 Access 时要打开的默认表单。我打开工具>启动并从启动的“显示/表单/页面”字段中删除了缺少的表单名称。我的问题解决了。

回答by Dan

The problem I was having is that the form was named ~TMPCLP8151 and would not show up in Access no matter what I tried, but I could see it in VBA in the Project Explorer. Here's how I resolved the issue. I created a new form, and created an Event Procedure for Form_Open that contained this: DoCmd.DeleteObject acForm, "~TMPCLP8151"

我遇到的问题是该表单被命名为 ~TMPCLP8151 并且无论我尝试什么都不会显示在 Access 中,但我可以在项目资源管理器的 VBA 中看到它。这是我解决问题的方法。我创建了一个新表单,并为 Form_Open 创建了一个包含以下内容的事件过程: DoCmd.DeleteObject acForm, "~TMPCLP8151"

Then I just opened the form, and sure enough, the VB code deleted the form that I could not delete myself.

然后我刚打开表格,果然,VB代码把我自己删不掉的表格给删了。

回答by Rollin Shultz

I had this problem. I renamed my default form from Form Login to frmLogin which suits my naming style, but the program was still looking for it on opening. I am using 2013 so I went to File ? Options ? CurrentDB and in the display dropdown select the new name. The old name remains in the list until you close and restart the application.

我有这个问题。我将我的默认表单从 Form Login 重命名为 frmLogin,这符合我的命名风格,但程序仍在打开时寻找它。我使用的是 2013,所以我去了 File ? 选项 ?CurrentDB 并在显示下拉列表中选择新名称。旧名称保留在列表中,直到您关闭并重新启动应用程序。

回答by THEn

I had a same problem. I created a form with same name and deleted the form again. That fixed the peoblem. Try. BTW try to open the new form in design mode to make sure if the VBA module is assosiated with the new form.

我有同样的问题。我创建了一个同名的表单并再次删除了该表单。这解决了问题。尝试。顺便说一句,尝试在设计模式下打开新表单,以确保 VBA 模块是否与新表单相关联。

回答by THEn

I had to combine both solutions to achieve the goal. First de- and recompile next compact and repair then create new form with the same name and delete it Pay attention that the form has the status Hasmodule set to Yes

我必须结合这两种解决方案来实现目标。首先反编译下一个压缩和修复然后创建同名的新表单并删除它注意表单的状态 Hasmodule 设置为 Yes