在多个 Access 数据库中使用集中式 VBA 模块

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

Using a centralized VBA module in multiple Access databases

ms-accessvbaaccess-vba

提问by spudsy

I've been put in charge of 50+ Access databases (.mdb's and .accdb's of varied versions) spread around an intranet, and I need to add a few VBA functions (the exact same code) to almost all of them. I'm hoping it can be accomplished by creating a reference from each database to a centralized VBA module, as I'd really like the ability to make changes down the road that are automatically replicated in every database. It would also be a bonus if any additional references in the central db could be kept intact so I wouldn't have to manage them individually as well.

我已经负责 50 多个 Access 数据库(.mdb 和 .accdb 的各种版本)分布在内部网中,我需要向几乎所有这些数据库添加一些 VBA 函数(完全相同的代码)。我希望它可以通过从每个数据库创建一个对集中 VBA 模块的引用来完成,因为我真的很希望能够在每个数据库中自动复制更改。如果中央数据库中的任何其他引用可以保持完整,那么我也不必单独管理它们,这也将是一个奖励。

I'm pretty new to VBA programming (although I've been a PHP junky for years), and have been having a hard time coming up with the right words to search for this particular issue. I think (from what I've read so far) that I might need Visual Studio to compile a DLL to reference, but I'd like to keep everything simple and contained within Access if possible, especially since we don't have a VS license.

我是 VBA 编程的新手(尽管我多年来一直是 PHP 迷),并且一直很难想出正确的词来搜索这个特定问题。我认为(根据我到目前为止所读到的内容)我可能需要 Visual Studio 来编译一个 DLL 以进行引用,但如果可能的话,我想保持一切简单并包含在 Access 中,尤其是因为我们没有 VS执照。

Thanks, any pointers would be much appreciated!

谢谢,任何指针将不胜感激!

回答by PowerUser

Don't worry, it's quite simple.

别担心,这很简单。

  1. Make your "helper" database. Put a few procedures in there.
  2. In your 'client' databases, open the VBA Editor
  3. Go to Tools->References. Browse and select your helper database.
  4. Done! You can now use all the functions in your helper database throughout your client databases.
  1. 制作您的“帮手”数据库。把一些程序放在那里。
  2. 在您的“客户”数据库中,打开 VBA 编辑器
  3. 转到工具-> 参考。浏览并选择您的助手数据库。
  4. 完毕!您现在可以在整个客户端数据库中使用助手数据库中的所有功能。

So... no .dll files to worry about. No Visual Studio needed.

所以...无需担心 .dll 文件。不需要 Visual Studio。

回答by Tony Toews

The search term is add-ins. (Ahh, I see Google has improved the search experience with words with embedded hyphnes since the last time I tried.) the approach mentioned by PowerUser will work but there are a number of issues.

搜索词是加载项。(啊,我看到自从我上次尝试以来,谷歌已经改善了带有嵌入连字符的单词的搜索体验。)PowerUser 提到的方法是可行的,但存在许多问题。

  • You will want to distrubte the add-in along with your FE to the users PCs.

  • An MDE/ACCDE cannot reference an MDB/ACCDB. But if you change the add-in MDE/ACCDE you must redistribute the FE MDE/ACCDE as well. Even though you didn't make any changes to the parameters or subroutine/function names.

  • While you are debugging the code in the add-in or dealing with an error message VBA will open the add-in VBA code editor. Do NOT make changes there. They will be lost as soon as you close the add-in code window.

  • 您将希望将加载项与您的 FE 一起分发给用户 PC。

  • MDE/ACCDE 不能引用 MDB/ACCDB。但是,如果您更改插件 MDE/ACCDE,您也必须重新分发 FE MDE/ACCDE。即使您没有对参数或子例程/函数名称进行任何更改。

  • 当您在加载项中调试代码或处理错误消息时,VBA 将打开加载项 VBA 代码编辑器。不要在那里进行更改。一旦关闭加载项代码窗口,它们就会丢失。

See my Add-in Tips, Hints and Gotchaspage for more details.

有关更多详细信息请参阅我的插件提示、提示和陷阱页面。

回答by awrigley

You could also take it a step further. I wrote an article on this for vb123.com:

你也可以更进一步。我为 vb123.com 写了一篇关于此的文章:

Using Database Library Files in your Access Application

在 Access 应用程序中使用数据库库文件

You can use forms, reports, queries, modules, classes... Pretty much everything except subforms. And all in a plain old mdb or accdb file (or mde, for that matter).

您可以使用表单、报告、查询、模块、类……除了子表单之外的几乎所有东西。所有这些都在一个普通的旧 mdb 或 accdb 文件(或 mde,就此而言)。