How can AllowBypassKey be enabled conditionally?

I have an Access application (database, forms etc.), in which I need to allow the autoExec bypass (Shift+Enter) only to admin users. How is that possible? Where should I put the code in order to run on Application startup?

The database has user-level security with the use of an .mdw file.

Thank you in advance,
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The simplest way is to provide the user with a button in the application that will reset that property:

Currentdb.Properties("AllowBypassKey") = True

The user would have to restart (these types of properties cannot be changed in the same session), so you could use a MsgBox to remind them of that.

To change it back:

Currentdb.Properties("AllowBypassKey") = False

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
Just wondering, why would you want admins to be able to open the application with the shift-bypass.  Realistically, only the developer needs to be able to do that.  If changes need to be made, they should be made to the developers version of the database, not the users.

To do this programmatically, from outside that database, you could use code similar to:

dim db as dao.database
set db = dbengine.OpenDatabase("C:\filename.accdb")
db.Properties("AllowBypassKey") = True   'or false

Or, you could use a launcher application.  My launcher application allows my users to select which application they want to launch and then copies the latest version of that application to the C:\Users\username\AppData\Roaming\MyApplications folder every time they run the launcher.  The file that gets copied is sitting on the server.  I would be easy to add a field to the Users table to determine whether the user is an Admin or not, and then copy the version with or without the shift-bypass to their computer.

The Publish subroutine in my applications includes code that automatically sets the AllowBypassKey property to False.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
If you've PROPERLY enabled ULS, then Dale's routines won't work, since you'd not be able to do that from outside the db without properly setting up the workgroup file.

If you have not properly enabled ULS (which is fairly common), then that may work.

Dale's suggestion of a launcher that could copy over the correct FE would probably be the simplest way to do things, if you don't like the idea of doing it in the app itself and then restarting the app, as I suggested.
Jeffrey CoachmanMIS LiasonCommented:
A few other notes:
Like Dale, mentioned, might want to clarify what your designation of "Admin" means.
Technically there is a difference between a Developer and an Administrator
A developer might, primarilly, be responsible for the Design of the DB.
(Form, Reports, queries, table design and relationships, ...vba code, ...etc)
An "Admin" would be responsible for dictating who has access to what objects/features
For example, an Admin would set up the user-level security.
The Admin would also be resonsible for communicating to the developer what features are needed.

In very broad terms, (for small/medium Access databases) you might have one Developer and one Administrator.
(In many cases this might be the same person)
Bypassing the start up options should only be reserved for a person who can have access to "All" database feature and functions.
So when you say "Admins"... should think very carefully about having multiple people being able to do whatever they wanted in the database...

So in your case, might want to take a closer look at your ULS settings and see if you can manage Developers and Admins more effectively with those settings.
Particularly "Full Data Users" and/or "Project Designers"
(Clicking on each of those groups will tell you what they can, and cannot do.)
Security Groups
mkaragAuthor Commented:
Thanks a lot. I had done the same as Scott described, but I expected to take effect real-time. Thus, I have to restart the application in order to change the property effectively.

As for the user groups, the database has only Simple Users and Admins/Developers.

Thanks again all of you for the contribution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.