This is a collection of standalone VBA libraries for MS Access projects. This is a WIP, I do not suggesting using in any sort of production project at this time.
The basic idea is to pull libraries references into your main project programmatically and automatically. To do this, we can save all libraries as .accda
files, and place them all in a folder called libraries
, then when the database is opened, we loop through these libraries and add them as references to your project.
This keeps your main application clean, with only the business logic unique to your project while still benefiting from useful, reusable, libraries of code. This is, in my opinion, a much better option than copying and pasting random code into your project.
First time installing the project at work. Attempted to use the flow as intented, realized a huge flaw in the plan. Your all probably familiar with the "Enable Content" popup for enabling VBA/Macros that end users must select in order for your code to run. The problem with the "seperate" libraries is, Access requires that users enable code for all libraries. I knew this, but when developing locally and actively editing the source files it totally slipped my mind.
This may, or may not, be a big issue for your use case. For me, the applications I would be builing have upwards of 30 users, many of which I will never meet. So it is not really a viable option to have end users enable all these libaries.
My thought at the moment is to create the ability for developers to "build" the production database, this process would involve importing all used code into the primary database when getting ready to release the database. But until I flesh this idea out more, I will be putting this project on a temporary hold.
- Download the library(ies) that you want to use
- Create a
libraries
folder in your project root - Add the
addReferences
function below to your main project - Ensure that this
addReferences
function is called when you open the database
Public Function addReferences()
On Error Resume Next
Dim fileObj, FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each fileObj In FSO.GetFolder(Application.CurrentProject.path & "\libraries").files
If FSO.GetExtensionName(fileObj.path) = "accda" Then
Application.References.AddFromFile fileObj.path
End If
Next
End Function
To use any public function defined in the libaries, simpy call them. If there may be a case where you have the same function defined in your main project, call the function specifically from the library, for example libraryName.functionName
The Auth library will provide an flexible, easy to use, authentication system for controlling access to your database.
The Env library provides easy access to various windows enviroment paths/values.
The Filesystem library provides easy to use methods for common filesystem tasks such as creating/deleting files/folders.
The Http library will provide easy to use methods for performing HTTP requests, and handling responses.
The Logger library will provide easy to use and configure methods to log errors and activity in your database.
The Middleware library will provide an flexible, easy to use, authorization system for managing roles and permission for your database.
The Outlook library will provide easy to use and configure methods to perform common tasks in MS Outlook.
The SQL library will provide easy to use and configure methods to perform SQL tasks (inserts, deletes, etc) in VBA for your database.
The SourceControl library provides an easy way to export all VBA modules in your database(s) for checking into source control. For an example, the src
files in this repo were exported from their respective databases using the SourceControl library. This library is mainly to aide in the maintenance of this repo, but you may find a use for it.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
I'd love to hear your thoughts on this proposed architecture, reach out to me on twitter