First Published 22 Sept 2022
This is a companion to my recent article: Create ACCDB & ACCDE Files using code
The standard method of compiling your VBA project is to click Debug . . . Compile in the Visual Basic Editor (VBE)
When the code is fully compiled, the Compile menu item is disabled ('greyed out').
Although this method is fine for most purposes, there are occasions when it is useful to do this using code.
For example, when creating a new template database and copying one or more code modules to that database
There is no standard VBA code to compile all modules. However, it can be done using the undocumented SysCmd 504 function.
Like all undocumented code, it is not officially supported by Microsoft and may in theory be removed at any time.
However, the code has been in existence for at least 20 years and it is unlikely to be removed any time soon.
For this code to work successfully, there must be no compile errors in your code modules. To run the code on the current database, use the following code:
Application.SysCmd 504, 16483
Or if you want to use the code to compile all modules in an external database, use the following code:
Dim app As Access.Application
Dim strPath As String
strPath = "Full path to your database here"
'open external database
'save & compile all modules
app.SysCmd 504, 16483
I hope this code will be useful to some of you.
Colin Riddington Mendip Data Systems Last Updated 22 Sept 2022
Return to Code Samples Page
Return to Top