Disable Shift Key

Posted on 2009-12-17
Last Modified: 2012-05-08
Hello Everyone, I am a database used both in Access 2003 & 2007, Is there a way to disable a user from pressing the Shift key or the PF11 Key and gain access to the Tables?
Question by:joeserrone
    LVL 8

    Expert Comment


    To prevent a user bypassing the start-up options you will need to apply the following function and code to a command button (or ideally a hidden option, such as to the double-click event of a label or graphic).
    This will prevent anyone without the password bypassing the start-up by using the Shift key.
    The below function and command button code will allow you to use a password protected input box to determine if the Shift key can be disabled or not.
    You might have to set your "References" in the VBA editor to DAO 3.6.
    When you are viewing a Module, click the Tools menu » References. Browse for Microsoft DAO 3.6
    Select "Files of type: Executable Files (*.exe; *.dll)"
    C:\Program Files\Common Files\Microsoft Shared\DAO)
    Then explicitly dimension yourcode, i.e. Dim db As DAO.Database, prp As DAO.Property
    '***************** Code Start ***************
    'Copy this function into a new public module.
    Option Compare Database
    Option Explicit
    Public Function SetProperties(strPropName As String, _
    varPropType As Variant, varPropValue As Variant) As Integer
        On Error GoTo Err_SetProperties
        Dim db As DAO.Database, prp As DAO.Property
        Set db = CurrentDb
        db.Properties(strPropName) = varPropValue
        SetProperties = True
        Set db = Nothing
        Exit Function
        If Err = 3270 Then    'Property not found
            Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
            db.Properties.Append prp
            Resume Next
            SetProperties = False
            MsgBox "SetProperties", Err.Number, Err.Description
            Resume Exit_SetProperties
        End If
    End Function
    '***************** Code End ***************
    Once you have created the module, then you will need to attach the following code to a command button (or label, graphic etc.):
    '***************** Code Start ***************
    'Assign this to the OnClick event of a command button (or double-click event
    'of a label or graphic) named "bDisableBypassKey"
    'Change the "TypeYourBypassPasswordHere" default password to your password
    Private Sub bDisableBypassKey_Click()
        On Error GoTo Err_bDisableBypassKey_Click
        'This ensures the user is the programmer needing to disable the Bypass Key
        Dim strInput As String
        Dim strMsg As String
        strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
                 "Please key the programmer's password to enable the Bypass Key."
        strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
        If strInput = "TypeYourBypassPasswordHere" Then
            SetProperties "AllowBypassKey", dbBoolean, True
            MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
                   "The Shift key will allow the users to bypass the startup & _
                   options the next time the database is opened.", _
                   vbInformation, "Set Startup Properties"
            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 & _
                   startup options the next time the database is opened.", _
                   vbCritical, "Invalid Password"
            Exit Sub
        End If
        Exit Sub
        MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
        Resume Exit_bDisableBypassKey_Click
    End Sub
    '***************** Code End ***************Once this is in place, a user will not have access to bypass the Start-Up options.
    As the administrator, you can then click on your command button, label or graphic and will be presented with a input box prompt to enter the bypass password: Please key the programmer's password to enable the Bypass Key.
    If the correct password is entered you will see a message: The Shift key will allow the users to bypass the startup  options the next time the database is opened. 
    An inncorrect password will give the following message and not allow the Shift key to bypass the Start-Up options: The Bypass Key was disabled. 
    The Shift key will NOT allow the users to bypass the  startup options the next time the database is opened. 
    Note: Always create a backup copy of the database, to test out any areas that may cause problems when working with start-up options or disabling Access features.

    Open in new window

    LVL 8

    Expert Comment


    1. Create a new module and past this code inside it:
    Option Compare Database
    Option Explicit
    Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
       Dim dbs As Object, prp As Variant
       Const conPropNotFoundError = 3270
       Set dbs = CurrentDb
       On Error GoTo Change_Err
       dbs.Properties(strPropName) = varPropValue
       ChangeProperty = True
       Exit Function
       If Err = conPropNotFoundError Then    ' Property not found.
           Set prp = dbs.CreateProperty(strPropName, _
               varPropType, varPropValue)
           dbs.Properties.Append prp
           Resume Next
           ' Unknown error.
           ChangeProperty = False
           Resume Change_Bye
       End If
    End Function
    Function BypassKey(onoff As Boolean)
       Const DB_Boolean As Long = 1
       ChangeProperty "AllowBypassKey", DB_Boolean, onoff
    End Function
    '-----------------------------------------------------------------------Then save the module to whatever you like.
    2. Create the macros.
    2.1 Macro Name: ByPassKeyOff
    Action: Runcode
    Function: BypassKey(False)
    2.2 Macro Name: ByPassKeyOn
    Action: Runcode
    Function: BypassKey(True)
    3. On your switchboard or logon screen create a rectangle with the same backcolor as the form and no border. Remember where it is. Or if you have a picture you can use it aswell. On the properties of the rectangle or picture select the Event tab->OnClick. Use the picker to select the ByPassKeyOn macro.
    4. Run the ByPassKeyOff macro. Save and close the db.
    5 Now when you start up and hold the shift key the db window will not show. To allow the shift key click where you put your rectangle or click the picture and close the db. Re-open with the shift key and the database window will appear. To disable do step 4.
    There you go. Just another way to make sure your database is secure. 

    Open in new window

    LVL 75

    Accepted Solution

    Here is a link with a sample database that has everything you need ... allows you to enable and disable - from another MDB ... to a target mdb:

    Scroll down to 'By Pass Shift Key Code'

    Another good link:


    Author Closing Comment

    All great examples and links

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now