Using a centralized VBA module in multiple Access databases

蓝咒 提交于 2019-12-17 17:58:14

问题


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.

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.

Thanks, any pointers would be much appreciated!


回答1:


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.

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




回答2:


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.

  • 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.

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




回答3:


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

Using Database Library Files in your Access Application

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).



来源:https://stackoverflow.com/questions/4168674/using-a-centralized-vba-module-in-multiple-access-databases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!