Solved Enable Default Shortcut Menus (1 Viewer)

dawsonrhodes

Member
Local time
Yesterday, 22:29
Joined
Mar 8, 2020
Messages
85
Hey guys,

I've got a database that I'm building that will be used by hundreds of people per day, per property at my company. To limit the possibility of design changes etc, I've created a login screen and on startup have disabled basically every menu and toolbar, as the database is made to be navigated solely by the use of buttons.

What I'd like, and already have, is a button that prompts for a password, which then allows me to edit and tinker as I please.

I am aware that the shift key will bypass any settings, but once I solve this issues, I intent on disabling this to ensure max security and privacy of records and design.

So in short, what I need is a command in VBA that enables the shortcut menus (the right click on objects in the left nav panel that has design view, layout, properties, etc.)

Here's what I have so far, minus the code for this setting I am asking for.

Code:
Private Sub btnEXAMPLE_Click()

    Dim x As Integer
    For x = 1 To 1
        Dim strInput As String, strMsg As String
            strMsg = "Enter Management Password"
                strInput = InputBox(prompt:=strMsg, title:="Password Required", xpos:=2000, ypos:=2000)
                    If strInput = "PASSWORD" Then
                        CurrentDb.Properties("ShowDocumentTabs").Value = True
                        DoCmd.ShowToolbar "Ribbon", acToolbarYes
                        DoCmd.SelectObject acTable, , True

    Exit Sub
    Else
    Dim msg, style, title, response
        msg = "Password Incorrect"
        style = vbOKOnly + vbExclamation
        title = "Password error"
        response = MsgBox(msg, style, title)
    End If
    Next x
Exit_Command3_Click:
    Exit Sub
   
End Sub

Thanks guys!
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:29
Joined
Oct 29, 2018
Messages
21,455
Hi. You won't need anything if you simply keep a "master" copy of the FE for your design changes. You can make all the updates you want on that copy and simply deploy a secured copy of it to your users.
 

dawsonrhodes

Member
Local time
Yesterday, 22:29
Joined
Mar 8, 2020
Messages
85
Hi. You won't need anything if you simply keep a "master" copy of the FE for your design changes. You can make all the updates you want on that copy and simply deploy a secured copy of it to your users.
Hey there,

thanks for your reply, I currently do this, however, since this is done remotely, I often use teamviewer to go in and diagnose from their side of things. I guess this is also wanted to protect my work from reproduction, etc. Any chance there is a code that either can enable the menus on load, or that will disable the forms menu when I load one form?


EDIT: Disregard, I found this forum you bookmarked, and will use this to fix my issue!


Thanks buddy.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:29
Joined
Oct 29, 2018
Messages
21,455
Hey there,

thanks for your reply, I currently do this, however, since this is done remotely, I often use teamviewer to go in and diagnose from their side of things. I guess this is also wanted to protect my work from reproduction, etc. Any chance there is a code that either can enable the menus on load, or that will disable the forms menu when I load one form?


EDIT: Disregard, I found this forum you bookmarked, and will use this to fix my issue!


Thanks buddy.
Nice! Good luck with your project.
 

dawsonrhodes

Member
Local time
Yesterday, 22:29
Joined
Mar 8, 2020
Messages
85
Nice! Good luck with your project.
Hey there,

I've actually tried this code and it won't work at all.

Code:
'** This code to allow (Bypass Key) ensures the user is the programmer needing to disable the Bypass Key  **
Private Sub bDisableBypassKey_DblClick(Cancel As Integer)
On Error GoTo Err_bDisableBypassKey_Click
    Dim strInput As String
    Dim strMsg As String
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
             "Please key the Super admin's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    If strInput = "ff887788" Then '<<<<<<<<<< Type the password between the double coats "ff887788"
        SetProperties "AllowBypassKey", dbBoolean, True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup." & vbCrLf & vbLf & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
    Else
        Beep
        SetProperties "AllowBypassKey", dbBoolean, False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the" & vbCrLf & vbLf & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
        Exit Sub
    End If
Exit_bDisableBypassKey_Click:
    Exit Sub
Err_bDisableBypassKey_Click:
    MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
    Resume Exit_bDisableBypassKey_Click
End Sub
'** End of code for Bypass key   ***************************************************************************

For whatever reason, this SetProperties "AllowBypassKey", dbBoolean, True just does not work for me, any ideas?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 19:29
Joined
Oct 29, 2018
Messages
21,455
Did you close and reopen the db?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:29
Joined
May 7, 2009
Messages
19,229
you are missing the SetProperties sub/function.
Code:
'** This code to allow (Bypass Key) ensures the user is the programmer needing to disable the Bypass Key  **
Private Sub bDisableBypassKey_DblClick(Cancel As Integer)
'arnelgp
Const PROP_NAME As String = "AllowBypassKey"
Const PROP_TYPE As Integer = dbBoolean
On Error GoTo Err_bDisableBypassKey_Click
    Dim strInput As String
    Dim strMsg As String
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
             "Please key the Super admin's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    If strInput = "ff887788" Then '<<<<<<<<<< Type the password between the double coats "ff887788"
        CurrentDb.Properties(PROP_NAME) = True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup." & vbCrLf & vbLf & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
    Else
        Beep
        CurrentDb.Properties(PROP_NAME) = False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the" & vbCrLf & vbLf & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
        Exit Sub
    End If
Exit_bDisableBypassKey_Click:
    Exit Sub
Err_bDisableBypassKey_Click:
    If Err.Number = 3270 Then
        CurrentDb.Properties.Append CurrentDb.CreateProperty(PROP_NAME, PROP_TYPE, True)
        Resume
    End If
    MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
    Resume Exit_bDisableBypassKey_Click
End Sub
'** End of code for Bypass key   ***************************************************************************
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:29
Joined
May 7, 2009
Messages
19,229
Code:
'** This code to allow (Bypass Key) ensures the user is the programmer needing to disable the Bypass Key  **
Private Sub bDisableBypassKey_DblClick(Cancel As Integer)
On Error GoTo Err_bDisableBypassKey_Click
    Dim strInput As String
    Dim strMsg As String
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
             "Please key the Super admin's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    If strInput = "ff887788" Then '<<<<<<<<<< Type the password between the double coats "ff887788"
        SetProperties "AllowBypassKey", dbBoolean, True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup." & vbCrLf & vbLf & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
    Else
        Beep
        SetProperties "AllowBypassKey", dbBoolean, False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the" & vbCrLf & vbLf & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
        Exit Sub
    End If
Exit_bDisableBypassKey_Click:
    Exit Sub
Err_bDisableBypassKey_Click:
    If Err.Number = 3270 Then
        CurrentDb.Properties.Append CurrentDb.CreateProperty(PROP_NAME, PROP_TYPE, True)
        Resume
    End If
    MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
    Resume Exit_bDisableBypassKey_Click
End Sub
'** End of code for Bypass key   ***************************************************************************

'arnelgp
Public Sub SetProperties(ByVal PropertyName As String, PropertyType As DataTypeEnum, PropertyValue As Variant)
    Dim dbs As DAO.Database
    Dim prp As DAO.Property
On Error GoTo err_handler:
    Set dbs = CurrentDb
    dbs.Properties(PropertyName) = PropertyValue
exit_sub:
    Set dbs = Nothing
err_handler
    If Err.Number = 3270 Then
        Set prp = dbs.CreateProperty(PropertyName, PropertyType, PropertyValue)
        dbs.Properties.Append prp
    End If
    Resume exit_sub
End Sub
 

dawsonrhodes

Member
Local time
Yesterday, 22:29
Joined
Mar 8, 2020
Messages
85
Code:
'** This code to allow (Bypass Key) ensures the user is the programmer needing to disable the Bypass Key  **
Private Sub bDisableBypassKey_DblClick(Cancel As Integer)
On Error GoTo Err_bDisableBypassKey_Click
    Dim strInput As String
    Dim strMsg As String
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
             "Please key the Super admin's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    If strInput = "ff887788" Then '<<<<<<<<<< Type the password between the double coats "ff887788"
        SetProperties "AllowBypassKey", dbBoolean, True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup." & vbCrLf & vbLf & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
    Else
        Beep
        SetProperties "AllowBypassKey", dbBoolean, False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the" & vbCrLf & vbLf & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
        Exit Sub
    End If
Exit_bDisableBypassKey_Click:
    Exit Sub
Err_bDisableBypassKey_Click:
    If Err.Number = 3270 Then
        CurrentDb.Properties.Append CurrentDb.CreateProperty(PROP_NAME, PROP_TYPE, True)
        Resume
    End If
    MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
    Resume Exit_bDisableBypassKey_Click
End Sub
'** End of code for Bypass key   ***************************************************************************

'arnelgp
Public Sub SetProperties(ByVal PropertyName As String, PropertyType As DataTypeEnum, PropertyValue As Variant)
    Dim dbs As DAO.Database
    Dim prp As DAO.Property
On Error GoTo err_handler:
    Set dbs = CurrentDb
    dbs.Properties(PropertyName) = PropertyValue
exit_sub:
    Set dbs = Nothing
err_handler
    If Err.Number = 3270 Then
        Set prp = dbs.CreateProperty(PropertyName, PropertyType, PropertyValue)
        dbs.Properties.Append prp
    End If
    Resume exit_sub
End Sub
Hey arnelgp,

Thanks for your code and help!

I've tried this and got an error, "err_handler" was missing a ":" so that' works now, now it disabled the key, but now can't enable it, I have a backup before I added your code, so I'll make a few copies of that and try to figure it out. Any reason why this would happen?

It also does not display any message boxes for me?

Thanks!
 

Pac-Man

Active member
Local time
Today, 07:29
Joined
Apr 14, 2020
Messages
414
Hey there,

I've actually tried this code and it won't work at all.

Code:
'** This code to allow (Bypass Key) ensures the user is the programmer needing to disable the Bypass Key  **
Private Sub bDisableBypassKey_DblClick(Cancel As Integer)
On Error GoTo Err_bDisableBypassKey_Click
    Dim strInput As String
    Dim strMsg As String
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
             "Please key the Super admin's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    If strInput = "ff887788" Then '<<<<<<<<<< Type the password between the double coats "ff887788"
        SetProperties "AllowBypassKey", dbBoolean, True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
               "The Shift key will allow the users to bypass the startup." & vbCrLf & vbLf & _
               "options the next time the database is opened.", _
               vbInformation, "Set Startup Properties"
    Else
        Beep
        SetProperties "AllowBypassKey", dbBoolean, False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
               "The Bypass Key was disabled." & vbCrLf & vbLf & _
               "The Shift key will NOT allow the users to bypass the" & vbCrLf & vbLf & _
               "startup options the next time the database is opened.", _
               vbCritical, "Invalid Password"
        Exit Sub
    End If
Exit_bDisableBypassKey_Click:
    Exit Sub
Err_bDisableBypassKey_Click:
    MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
    Resume Exit_bDisableBypassKey_Click
End Sub
'** End of code for Bypass key   ***************************************************************************

For whatever reason, this SetProperties "AllowBypassKey", dbBoolean, True just does not work for me, any ideas?
Hi,

Have you tried following code befoe running your code to set the AllowBypassKey property. This property doesn't exist in a database by default. You need to create and spend it to db properties. Just put the following code in a standard module and press F5 while your cursor is inside the function.

Code:
Function fCreateAllowBypassKey()
        Dim prp As Property
        Set prp = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
        CurrentDb.Properties.Append prp
End Function

After using it, you can delete the function of you want.

Hope it helps.

Best Regards,
Abdullah
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:29
Joined
May 7, 2009
Messages
19,229
Code:
'arnelgp
Public Sub SetProperties(ByVal PropertyName As String, PropertyType As DataTypeEnum, PropertyValue As Variant)
    Dim dbs As DAO.Database
    Dim prp As DAO.Property
On Error GoTo err_handler
    Set dbs = CurrentDb
    dbs.Properties(PropertyName) = PropertyValue
exit_sub:
    Set dbs = Nothing
err_handler:
    If Err.Number = 3270 Then
        Set prp = dbs.CreateProperty(PropertyName, PropertyType, PropertyValue)
        dbs.Properties.Append prp
    End If
    Resume exit_sub
End Su
 

dawsonrhodes

Member
Local time
Yesterday, 22:29
Joined
Mar 8, 2020
Messages
85
Code:
'arnelgp
Public Sub SetProperties(ByVal PropertyName As String, PropertyType As DataTypeEnum, PropertyValue As Variant)
    Dim dbs As DAO.Database
    Dim prp As DAO.Property
On Error GoTo err_handler
    Set dbs = CurrentDb
    dbs.Properties(PropertyName) = PropertyValue
exit_sub:
    Set dbs = Nothing
err_handler:
    If Err.Number = 3270 Then
        Set prp = dbs.CreateProperty(PropertyName, PropertyType, PropertyValue)
        dbs.Properties.Append prp
    End If
    Resume exit_sub
End Su
Hey there,

I've tried adding this too, but it just freezes my database and doesn't change the property. Not sure where to go from here?
 

dawsonrhodes

Member
Local time
Yesterday, 22:29
Joined
Mar 8, 2020
Messages
85
Hi,

Have you tried following code befoe running your code to set the AllowBypassKey property. This property doesn't exist in a database by default. You need to create and spend it to db properties. Just put the following code in a standard module and press F5 while your cursor is inside the function.

Code:
Function fCreateAllowBypassKey()
        Dim prp As Property
        Set prp = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
        CurrentDb.Properties.Append prp
End Function

After using it, you can delete the function of you want.

Hope it helps.

Best Regards,
Abdullah
Hey there,

Thanks for your code, I tried this and it worked, the issue is I have been unable to re-enable it with a button. Any ideas?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:29
Joined
May 7, 2009
Messages
19,229
see this demo. double click on the Label.
 

Attachments

  • bypassRoad.accdb
    704 KB · Views: 517

Pac-Man

Active member
Local time
Today, 07:29
Joined
Apr 14, 2020
Messages
414
Thank you so much, I am not sure why it did not work me when I did, I've copies over the contents and will rename as needed!
Hi,

I hope @arnelgp sample db have solved your issue. Attached is an alternate approach that I usually follow for enabling and disabling AllowBypassKey property. I disable it on the OnLoad event of some Main form (frmMain in attached db) which is set to auto open on opening the database using Options>>Current Database >>Display Form and select frmMain from drop down list.

To enable it, I have a form frmDevOption which along with other developer specific option have a button to enable AllowBypassKey. This form is loaded after successful login of user by using frmDevLogin (which can be opened using a button or some label or title of the form). For the sample db, I have hard coded the username (Abdullah Khan) and password (AABBCC112233) however you can use other option such that users login with Access level control.
 

Attachments

  • AllowBypassDemo.zip
    660.9 KB · Views: 521

Pac-Man

Active member
Local time
Today, 07:29
Joined
Apr 14, 2020
Messages
414
Code:
'arnelgp
Public Sub SetProperties(ByVal PropertyName As String, PropertyType As DataTypeEnum, PropertyValue As Variant)
    Dim dbs As DAO.Database
    Dim prp As DAO.Property
On Error GoTo err_handler
    Set dbs = CurrentDb
    dbs.Properties(PropertyName) = PropertyValue
exit_sub:
    Set dbs = Nothing
err_handler:
    If Err.Number = 3270 Then
        Set prp = dbs.CreateProperty(PropertyName, PropertyType, PropertyValue)
        dbs.Properties.Append prp
    End If
    Resume exit_sub
End Su
@arnelgp thanks for this universal code to set property. I've bookmarked it and will be using it in the future instead of the function I shared in post# 10 (which I posted before seeing SetProperty part of your code.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 10:29
Joined
May 7, 2009
Messages
19,229
Abdullah, there is an error on that code.
You need to put Exit Sub after

Set dbs = Nothing
Exit Sub
 

Users who are viewing this thread

Top Bottom