MS Access 2007:查找使用表单/查询/报告的位置
历史:我继承了一个使用 MS Access 编写的相当大的应用程序,其中包含大量表单、查询和报告。因为其中一些项目看起来像是为了备份而复制的,所以我不知道它们是否真的在任何地方使用。
问题:我正在开始清理应用程序,需要一种方法来查找是否以及在何处使用表单、报告或查询,以便我知道是否可以删除或重构它们。有没有一个好方法让 Access 在按钮事件中搜索表单/报告的名称?
(Access 的查找功能似乎只能查找记录,除非我缺少设置)
编辑 - 解决方案:
1.) 正如下面的答案和评论中所提到的,通过创建一个新的 Access 文件然后逐个表单地重建应用程序将是一个宝贵的教训,从登录屏幕,看看缺少什么。这将为整个应用程序提供深入的了解。
2.)我发现这篇文章讨论了使用“数据库文档管理器”转储与给定表单中使用的对象、VBA 等相关的所有信息。使用单个特定查询、报告或表单可以轻松搜索生成的文本文件。它不会为我提供与重建整个应用程序相同水平的知识,但它是有针对性的知识/可能的清理的一个很好的权宜之计。
History: I inherited a rather large app written using MS Access with lots of forms, queries, and reports. Because it looks like some of these items that were copied as a way of backing them up, I've got no idea if they are actually used anywhere.
Question: I am starting the process of cleaning up the app and need a way to find if and where forms, reports, or queries are used so that I know if I can delete or refactor them. Is there a good way have Access search the events of buttons for the names of forms / reports?
(Access' find feature seems to find only records unless I'm missing a setting)
Edit - Solutions:
1.) As has been mentioned in the answers and comments below, it would be a valuable lesson to rebuild the application by creating a fresh Access file then going form by form, starting with the login screen, and seeing what is missing. This would provide great insight into the whole application.
2.) I found this post that discusses using the "Database Documenter" to dump out all of the information relating to the objects, VBA, etc used in a given form. The resulting text file is easily searchable for the use of a single particular query, report, or form. It would not provide me with the same level of knowledge as re-building the whole application would, but it is a good stop-gap measure for targeted knowledge / possible cleanup.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
假设您有一个名为 frmOne 的表单,其中有一个命令按钮,其隐藏代码为:
并且 rptFoo 使用 qryFoo 作为其记录源。
启用轨道名称自动更正,然后查看 frmOne 的对象依赖关系将不会通知您 frmOne 需要 rptFoo。但是它可以告诉您 qryFoo 是 rptFoo 所必需的。另一个问题是对象依赖项不会通知您 frmOne 已被弃用 --- 当前版本是 frmTwo。
同样,使用 Application.SaveAsText 为数据库对象创建文本文件,然后 grep 文本文件不会告诉您 frmOne 已被弃用。
您可以尝试不同的方法来确定需要哪些数据库对象。创建一个新的数据库文件。从旧数据库导入启动表单。打开新数据库和表单以识别所需的缺失项目。导入那些。起泡沫,冲洗,重复。
如果应用程序不是从启动表单驱动的,请询问用户他们使用哪些表单和报告,然后导入它们。
这种方法会很乏味,并且可能需要几个小时。然而,我怀疑其他方法会更快。从好的方面来说,您几乎可以保证不会将不需要的对象导入到新数据库中。如果您错过了任何需要的内容,您可以从旧数据库的保存副本中导入它。
Say you have a form named frmOne which has a command button with the code-behind as:
And rptFoo uses qryFoo as its record source.
Enabling Track Name Autocorrect, then viewing the Object Dependencies for frmOne will not notify you that rptFoo is required by frmOne. It can however tell you qryFoo is required by rptFoo. Another issue is the object dependencies will not notify you that frmOne has been deprecated --- the current version is frmTwo.
Similarly, using
Application.SaveAsText
to create text files for database objects, then grepping the text files would not tell you frmOne has been deprecated.You could try a different approach to identify which of the database objects are required. Create a new database file. Import the startup form from the old database. Open the new database, and the form to identify the missing items it needs. Import those. Lather, rinse, repeat.
If the application isn't driven from a startup form, ask the users which forms and reports they use, then import those.
This approach will be tedious, and could take a few hours. However, I doubt the other approaches would be dramatically faster. On the plus side, you're pretty much guaranteed that you won't be importing unneeded objects into the new database. And if you miss anything which is needed, you can import that from the saved copy of the old database.
这可能是使用“跟踪名称自动更正”的情况,打开此功能后,您可以跟踪对象依赖性。
使用 VBA 检查表单引用的代码和事件绝非不可能。
This may be a case for using Track Name Autocorrect, with this turned on you can trace object dependencies.
It is by no means impossible to check code and events for form references with VBA.
我继承了一个具有 20 多个 mdb 前端的应用程序,其中一些使用其他文件中的查询。除了 Remou 提到的解决方案之外,我还使用了此 脚本将所有表单、查询和报告导出到文本文件,然后通过 grep 检查对象是否已使用。
它并不完美,但它也允许我检查 mdb 之间的依赖关系 - 我不确定是否可以使用内置工具来执行此操作。当我编码时,我可能已经患上了 NIH。
您可能还想查看 mz-tools 它有一些工具可以查找未使用的代码。
I inherited an application with 20+ mdb front-ends with some of them using queries in other files. In addition to the solution that Remou mentioned, I also use a variation of this script to export all forms, queries, and reports to text files then grep through them to check if the object is used.
It's not perfect, but it also allows me to check for dependencies between mdbs - I'm not sure if you can do this with the built-in tools. I may have been suffering from NIH when I coded it up.
You may also want to look at mz-tools which has some tools to find unused code.
有一个免费且有用的小插件 vtools,除了其他可能性之外,特别允许您在所有访问对象(表、查询、代码、表单等)中搜索值或引用。
There is this small add-in, free and usefull vtools, that, among other possibilities, specifically allows you to search for values or references in all access objects (tables, queries, code, forms, ...).
这很容易。
进入 VBA 代码编辑器(在某处找到“查看代码”)
按 CTRL + F 调出查找选项,然后单击“搜索项目”,
这样,如果您浏览表单和报告名称,您将能够找到每次以编程方式引用它们的时间。这将无法查找是否使用了查询,因为您需要数据库文档管理器。
Its easy.
Go into the VBA code editor (find View Code somewhere)
CTRL + F to pull up the find options and click Search Project
so if you go through the form and report names you'll be able to find every single time they've been referenced programatically. This will not work to find if queries are used, for that you need the Database Documenter.