Disable Shift Key

Masked inputbox

I added this to my Disable-Shift routine to enter. It's been working for 3 years now.
Make a new module and paste this code into it.
Code:
Option Compare Database

Option Explicit
'////////////////////////////////////////////////////////////////////
'Password masked inputbox
'Allows you to hide characters entered in a VBA Inputbox.
'
'Code written by Daniel Klann
'March 2003
'////////////////////////////////////////////////////////////////////


'API functions to be used
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
                                                      ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" _
                                          (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, _
                                          ByVal dwThreadId As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long

Private Declare Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" _
                                            (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal wMsg As Long, _
                                            ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, _
                                                                          ByVal lpClassName As String, _
                                                                          ByVal nMaxCount As Long) As Long

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long

'Constants to be used in our API functions
Private Const EM_SETPASSWORDCHAR = &HCC
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Private Const HC_ACTION = 0

Private hHook As Long

Public Function NewProc(ByVal lngCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim RetVal
    Dim strClassName As String, lngBuffer As Long

    If lngCode < HC_ACTION Then
        NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
        Exit Function
    End If

    strClassName = String$(256, " ")
    lngBuffer = 255

    If lngCode = HCBT_ACTIVATE Then    'A window has been activated

        RetVal = GetClassName(wParam, strClassName, lngBuffer)

        If Left$(strClassName, RetVal) = "#32770" Then  'Class name of the Inputbox

            'This changes the edit control so that it display the password character *.
            'You can change the Asc("*") as you please.
            SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
        End If

    End If

    'This line will ensure that any other hooks that may be in place are
    'called correctly.
    CallNextHookEx hHook, lngCode, wParam, lParam

End Function

Public Function InputBoxDK(Prompt, Optional Title, Optional Default, Optional XPos, _
                        Optional YPos, Optional HelpFile, Optional Context) As String
    
    Dim lngModHwnd As Long, lngThreadID As Long

    lngThreadID = GetCurrentThreadId
    lngModHwnd = GetModuleHandle(vbNullString)

    hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)

    InputBoxDK = InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
    UnhookWindowsHookEx hHook

End Function

Use InputBoxDK(SomeCode) instead of inputbox(SomeCode) to call.
 
Sorry! (inputboxDK)

For some reason, I didn't see the same thing posted above when I was reading this forum. Looks like the same guy wrote it, altered code, modified a month later...LOL
 
Thank for sharing,

It does work!!!
 
hi
im developing database in access 2007. i need to bypass / disable the shift key at startup, thus not enabling the user to use the shift key and enable the navigation pane, default menu and access options.
i have gone through all the forum, searched a lot, tried the above given 2 solutions, also tried AllowBypassKey2kTo2k7 solution, referenced above, but im not able to get the result.
the solution given by ghudson shows no message box after password input, whether you input it correct or wrong.
the solution given by MadMaxx shows error number 2950.

im helpless...
can anyone help me pls!!!!!
 
Last edited:
sorry for the bounce but just wanted to pass on my thanks to ghudson for the code. It works brilliantly and ties in nicely with the admin function only I get access to.

Seriously thank you so much for sharing this code.
 
Thank you for the codes.

Can someone (not the .mdb's administrator but one of the restricted users configured in the .mdw) use the same code to enable the bypass shift key and open the entire database?

One more situation: as the .mdb and .mdw files are in the server, would this same person copy them into his own pc and use the code to enable the bypass key and then open the entire database?

It would be a big problem if both are possible.
 
What do you do if for some reason the shift bypass cannot be re-enabled by the button created? Is there any way to get past the startup screen. I am unable to get into the tables in the backend of a database now.
 
Hai Ghudson,
Your Module and Code for the Command Button on "Disbale Shift Key" gave me Life in Access. At a time I was quitting from Access because No Web Site helped me to over come by problem and concern, an intuition came in my mind to once again search the web. While browsing I came accross Access World Forum, found your Code, and I immediately copied it. Now my databases cannot be broken by the users by holding the Shift Key.
So Many Many Thanks. Let many people get benefitted by you. The Lord Jesus Bless You
 
Here is my solution to the shift key issue (Office 365 - A2013):

[
Code:
 '-------------------------------------------------------
' Shift key property
'-------------------------------------------------------
'
Public Function ShiftKeyProp(bl As Boolean)
    'This function enable/disable the usage of the shift key at startup.
    ' If disabled, Autoexec and Startup properties are always executed.
     On Error GoTo errDisableShift
     Dim db As DAO.Database
    Dim prop As DAO.Property
    Const conPropNotFound = 3270
    
    Set db = CurrentDb()
    
    'This next line sets the shift key usage on startup.
    db.Properties("AllowByPassKey") = bl
    
    'The function is successful.
    Exit Function
 errDisableShift:
    If Err = conPropNotFound Then
        'Create the "AllowByPassKey property and set it's value.
        Set prop = db.CreateProperty("AllowByPassKey", _
        dbBoolean, bl)
        db.Properties.Append prop
        Resume Next
    Else
        MsgBox "Function 'ap_DisableShift' did not complete successfully."
        Resume Next
    End If
 End Function
It is stored in a Utilities module.
 
Last edited:
IgorB, you can still disable/enable the shift key from within the secured db. The
db will have to be closed and reopened to be able to open the db 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" to DAO 3.6. When you are viewing
the module, click the Tools menu >>> References >>> and Browse for Microsoft
DAO 3.6 >>> Select "Files of type: Executable Files (*.exe; *.dll)"
My DLL was located @ C:\Program Files\Common Files\Microsoft Shared\DAO.

Copy this function into a new public module.
Code:
Public Function SetProperties(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
On Error GoTo Err_SetProperties
    
    'Dim db As Database, prp As Property
    Dim db As DAO.Database, prp As DAO.Property
    
    Set db = CurrentDb
    db.Properties(strPropName) = varPropValue
    SetProperties = True
    Set db = Nothing
    
Exit_SetProperties:
    Exit Function
    
Err_SetProperties:
    If Err = 3270 Then 'Property not found
        Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
        db.Properties.Append prp
        Resume Next
    Else
        SetProperties = False
        MsgBox "Runtime Error # " & Err.Number & vbCrLf & vbLf & Err.Description
        Resume Exit_SetProperties
    End If
    
End Function
Assign this to the OnClick event of a command (transparent?) button named "bDisableBypassKey".
Change the "TypeYourPasswordHere" default password.
This sub ensures the user is the programmer needing to disable the Bypass Key.
You can not format an Input Box!
Code:
Private Sub bDisableBypassKey_Click()
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 programmer's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    
    If strInput = "TypeYourPasswordHere" Then
        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 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 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 "Runtime Error # " & Err.Number & vbCrLf & vbLf & Err.Description
    Resume Exit_bDisableBypassKey_Click
    
End Sub
HTH

this is great works a treat keeps people out and thanks for sharing. Searched and found it, rather then posting asking same question for Nth time :cool:
 

Users who are viewing this thread

Back
Top Bottom