Setting Allow Bypass Key through VBA base on Security Level (1 Viewer)

PaulA

Registered User.
Local time
Today, 04:56
Joined
Jul 17, 2001
Messages
416
Greetings,

I am wanting to have a log on form that is coded that if a user has a specific user level value he will have a a message box open giving him the option to set the Bypass Key at true or false.

However, I want all other users not to have that message box generated so they would just open the main form with the bypass key not available to them.

I either get the option message box for all users or for no users.

I have tried various versions of the code but this is my basic one:

Code:
Dim AccessLevel As Integer
Dim prop As DAO.Property
            
Set prop = CurrentDb.CreateProperty("allowbypasskey", dbBoolean, False)
CurrentDb.Properties.Append prop

      If rs![AccessLevel] = 4 Then
        If MsgBox("Would you like to turn on the bypass key?", vbYesNo, "Allow ByPass") = vbYes Then
            CurrentDb.Properties("AllowBypassKey") = True
        Else            
          CurrentDb.Properties("AllowBypassKey") = False
    
        End If
     End If

The message box appears even if the AccessLevel is a value other than 4.

Any ideas?

Thanks.
 

isladogs

MVP / VIP
Local time
Today, 04:56
Joined
Jan 14, 2017
Messages
18,221
You haven't defined the recordset before the line

Code:
If rs![AccessLevel] = 4 Then
 

Cronk

Registered User.
Local time
Today, 13:56
Joined
Jul 4, 2013
Messages
2,772
If the recordset is not defined that would either give a compile error or I would have thought object not exists error.

Maybe the problem is with the recordsource and the where/filter condition.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:56
Joined
Feb 28, 2001
Messages
27,186
Well... maybe not. There are ways to do some things related to knowing who a user is, but this particular goal has a timing problem.

The Bypass key is something that you use when starting the database. It bypasses some of the settings in the File >> Options >> Current Database menu, things which apply to the startup process. Once the database has started, the Bypass key has no further function. Unfortunately, in order to put up a login form, your database has to already be past that point. I.e. trying to dynamically apply the Bypass key from a login form is already too late for it to do any good.

You CAN at run time (after a login) decide to re-enable the ribbon and set some other application settings. This forum has many articles on enabling and disabling certain features including the ribbon. Use the forum's SEARCH function to find articles about dynamically enabling or disabling certain developer features.
 

PaulA

Registered User.
Local time
Today, 04:56
Joined
Jul 17, 2001
Messages
416
Thanks for your input. I actually fixed the code he Doc Man hit the nail on the head. I would want the default for the database when opening to be that the bypass key will not work. Only when I turn it on (for myself only) would it be available.

Are you saying it really isn't possible to have the bypass function unavailable by default at the start of opening the db or even having the property set on closing? I put the code to set thy bypass property to false on an invisible form that would close when the database closes. Unfortunately, that didn't work. The bypass key worked anyway.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 22:56
Joined
Feb 28, 2001
Messages
27,186
I'm saying that you must start with bypass key disabled always.

What the bypass key does is it forces your database to take the values set using the options revealed by File >> Options >> Current Database.

Once the database is UP, however, there are ways to re-enable those options via program - which could occur AFTER your login (or as a result thereof). You need to look up the msdn article on the Access Bypass key to see what is actually bypassed, then look up those things to see how to dynamically re-enable them after login time. There are many articles in this forum that discuss variations on that theme.
 

Users who are viewing this thread

Top Bottom