Code Samples for Businesses, Schools & Developers
Last Updated 29 Nov 2019
This article shows how the UserControl property can be used to restrict how an application can be opened.
It was done partly in response to a recent thread by calvinie at Access World Forums:
Preventing user from opening accde directly but only via another access database
UserControl is a boolean property - True if opened direct, False if opened via another application using automation
See https://docs.microsoft.com/en-us/office/vba/api/access.application.usercontrol
Attached are two examples each containing a Starter app and a Main app, both with one form:
Just one line of code is required in the Form_Load event of the startup form or in an autoexec macro.
a) BlockDBOpenDirect (as in the original thread request)
The Main app can be opened via the Starter app but cannot be run directly.
Code:
If Application.UserControl = True Then Application.Quit
b) BlockDBRemoteAccess (the exact opposite)
The Main app can be run directly but cannot be opened remotely using automation
Code:
If Application.UserControl = False Then Application.Quit
NOTE:
I have used method b) in conjunction with other security measures such as disabling the shift bypass to help prevent hacking using automation.
However, no Access database can EVER be made 100% secure.
A capable and determined hacker can break any Access database given sufficient time and motivation.
Nevertheless, by erecting various barriers, it is possible to make the process so difficult and time consuming that it isn't normally worth attempting.
Click to download:
BlockDBOpenDirect (approx 0.5 MB - zipped)
BlockDBRemoteAccess (approx 0.5 MB - zipped)