Compilation Explained

In this blog post we will examine compilation and the effect it has on the code you write.

Compilation is the act of converting our human readable code ( VBA) into code the computer understands.  It may also be that your code is compiled into an intermediary format often called object code.  Either way, this just illustrates that our programs are actually just a human understandable representation of what we are telling our computers to do.

 6 Generally you will not notice the compiler as these setting on the left are set to automatically compile during execution and whilst you type.

You can explicitly force VBA IDE to compile all modules in the project.

Before you release your Access product to fellow users it is always a good idea to explicitly execute the Compile item in Debug menu.

 

Compiling before release ensures the VBA code executes as fast as possible.

 Screenshot 2014-06-13 16.25.57

Advanced Compilation and ACCDE

While compilation as described above allows your application to execute in a multiuser environment, it leaves all the form data, report data and VBA code available to be edited by anyone with a full installation of MS Access.

To combat this, we can create an ACCDE file in which all code has been compiled and cannot be altered. And when we say cannot we mean CANNOT! So, make a back-up of your database before converting so you always have the ability to alter the code you spent hours making.

Just to repeat:

MAKE A BACK UP OF YOUR DATABASE BEFORE DOING THIS OPERATION. 

To Create an ACCDE file:

 

Click on the File tab in the Ribbon to expose BackStage view.  8
Click on Save & Publish.  9
Click on Make ACCDE.  10
Click on Save As.  11
A Save As dialog box will pop up.

You choose where you would like to save the ACCDE file and under what name.

 12

Why use an ACCDE file?

Creating an ACCDE file removes all design code so that Forms may only be opened in Form View and Modules cannot be debugged. So even if the SHIFT Key open method is used, no Forms, Reports or Code can be changed.

This is useful for the following situations:

  • You don’t want users to change your forms, reports or code.
  • It creates a more stable Access Database for multi-user environments.
  • You want to protect your intellectual property.
  • You want to publish your Access Database.

Multi-Users Environments

From first-hand experience in multi-user environments you are advised to only give end-users ACCDE or MDE files and split your back- and front-ends.  Giving access to the ACCDB runs the possibility of inadvertent changes to form properties – e.g. when a user applies a filter to the form – and when saved this very well may corrupt your database.

Corrupt databases can be recovered but on the off-chance it is not possible it is not worth the risk. You’ll lose a day’s work at least (if not everything), if backups of your file server haven’t been kept.

Compilation is a concept worth understanding that will help you to distribute optimized databases to your clients.

Related Posts

Basic Tools for Writing Code
Debugging
Immediate Window
Opening The VBA Editor
The VBA Editor Explained
Visual Basic Editor Options

Leave a Reply

Your email address will not be published. Required fields are marked *

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube