1

I have multiple MS-Access 2003 project with some VBA code and there are some redundant functions that I would like to have in the same file. I thought about saving it in an external .bas module and loading it into all my projects. Is it possible? If so, how can we implement this and will I have to change the actual (simple) calls to my functions?

1 Answer 1

3

You can use the undocumented:

Application.SaveAsText acModule, "module1", "module1x.bas"
Application.LoadFromText acModule, "module1y", "module1x.bas"

Or you can simply save and load manually with right-click on the module name in the code window.

Finally, you can reference an Access application in the same way as any other reference, and then use the code. The file type *.mda was the library type. As far as I know, from 2007, you can create an *.accda library type.

Sign up to request clarification or add additional context in comments.

7 Comments

Not sure about the link provided. Didn't see anything about *.mda. The code does work however, the module is added to the project. But in fact, if I call for a function into the module, the code won't run at all, giving me an error message saying the function can't be found (even before the Application.LoadFromText can load the module). What I want is adding a *.bas file as reference. I have a ton of projects that make use of the same functions and I don't want to edit those functions in 10 different files.
Create a library reference, you can use the mda extension if you want office.microsoft.com/en-us/access-help/…
The 4 links in the page you provided are dead. Here is what I found on the MSDN: msdn.microsoft.com/en-us/library/office/…. Thanks for letting me know about MDA, it should get the job done.
It works like a charm. For some reason the FileSystemObject variable type isn't recognized anymore, I have to declare them in the module as Variant and then set 'em with CreateObject("Scripting.FileSystemObject"). But it works perfectly fine.
If the filesystemobject is not recognised, it is because you do not have a reference to the Windows Script Host Object Model - it is not a standard reference and must be added for each project. However, for the most part, it is better to use late binding with external libraries.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.