Link to home
Start Free TrialLog in
Avatar of jwah
jwahFlag for New Zealand

asked on

Preventing SHIFT key enabling access to Database window during startup (with MDE file)

I'm having some trouble with my Access 2000 app despite trying various VB code from the WWW.

I need a simple way to prevent users getting to the DB window using the F11 key( which I have easily disabled via the startup menu) AND more importantly preventing the SHIFT key doing anything.  I only distribute a MDE file so I don't need to get to the window via "their" MDE version. Does someone have some steps I can follow?

Avatar of dbase118
dbase118
Flag of United States of America image

Here are two links and the MS Access description of the ByPass Property


https://www.experts-exchange.com/questions/20635052/How-can-i-disable-shift-and-F11-in-access2000.html
https://www.experts-exchange.com/questions/11578699/Disable-SHIFT-key.html

AllowBypassKey Property
               

You can use the AllowBypassKey property to specify whether or not the SHIFT key is enabled for bypassing the startup properties and the AutoExec macro. For example, you can set the AllowBypassKey property to False to prevent a user from bypassing the startup properties and the AutoExec macro.

Setting

The AllowBypassKey property uses the following settings.

Setting Description
True (–1) Enable the SHIFT key to allow the user to bypass the startup properties and the AutoExec macro.
False (0) Disable the SHIFT key to prevent the user from bypassing the startup properties and the AutoExec macro.


You can set this property by using a macro or Visual Basic.

To set the AllowBypassKey property by using a macro or Visual Basic, you must create the property in the following ways:

In a Microsoft Access database (.mdb), you can add it by using the CreateProperty method and append it to the Properties collection of the Database object.


In a Microsoft Access project (.adp), you can add it to the AccessObjectProperties collection of the CurrentProject object by using the Add method.
Remarks

You should make sure the AllowBypassKey property is set to True when debugging an application.

This property's setting doesn't take effect until the next time the application database opens.
Avatar of 1William
1William

This code does it.  Just place in a module named 'basMain'
Option Compare Database
Option Explicit

Dim db As Database

Public Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim prp As Property
Const conPropNotFoundError = 3270

On Error GoTo Change_Err
    db.Properties(strPropName) = varPropValue
    ChangeProperty = True

Change_Bye:
    Exit Function

Change_Err:
    If Err = conPropNotFoundError Then  ' Property not found.
        Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
        db.Properties.Append prp
        Resume Next
    Else    ' Unknown error.
        ChangeProperty = False
        Resume Change_Bye
    End If
   
End Function

Function CheckDisableShiftKey()
Dim retval As Variant
Dim strCmdLine As String
 
    Set db = CurrentDb()
    strCmdLine = Command()
    'MsgBox strCmdLine
   
    If strCmdLine = "IntAdmin" Then
        ChangeProperty "StartupShowDBWindow", dbBoolean, True
        ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
        ChangeProperty "AllowFullMenus", dbBoolean, True
        ChangeProperty "AllowBreakIntoCode", dbBoolean, True
        ChangeProperty "AllowSpecialKeys", dbBoolean, True
        ChangeProperty "AllowBypassKey", dbBoolean, True
        ChangeProperty "AllowShortCutMenus", dbBoolean, True
        retval = Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" & Chr$(34) & " " & Chr$(34) & db.Name & Chr$(34), vbMaximizedFocus)
        'Debug.Print db.Name
        'MsgBox db.Name
        ChangeProperty "StartupShowDBWindow", dbBoolean, False
        ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
        ChangeProperty "AllowFullMenus", dbBoolean, False
        ChangeProperty "AllowBreakIntoCode", dbBoolean, False
        ChangeProperty "AllowSpecialKeys", dbBoolean, False
        ChangeProperty "AllowBypassKey", dbBoolean, False
        ChangeProperty "AllowShortCutMenus", dbBoolean, False
        DoCmd.Quit
    End If
   
End Function


To get in to see the db window, you need a special shortcut like this (change paths, ect to suit)

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\BypassShiftKey\BypassShiftKey.mdb" /cmd "IntAdmin"
Avatar of jwah

ASKER

I thought I would try 1Williams suggestion, which seems ok to follow. Many thanks.

but it is not working yet - a couple of things to check.
1. I have pasted the code into a new Module (basMain) and it compiled check was OK. I note that there is a declaration db as database. I use this variable elsewhere in functions. I hope this will be OK.

2. By the way I have a spilt database linked to tables but this should not be a problem.

3. With regard to the "The enabler" shortcut

"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "C:\BypassShiftKey\BypassShiftKey.mdb" /cmd "IntAdmin"

what is BypassShiftKey.mdb  does this get created automatically?  Shall I make this path the same place as my database?

4. To make it work how deos it first disable the KEY?  What settings to I need on the TOOLS STARTUP menu?

jwah
Avatar of jwah

ASKER

Sorry (it's early here*&*(&*) I have changed the shortcut to point to the database in question.

(The database window icon still appears despite things being turned off under TOOLS etc.)
********************************************************************************************************************
**********Make a Backup before you implement.  A error can lock it up and you may NEVER get it.  *************************************
********************************************************************************************************************

Sure.  I declare db once for the whole app, hence it is a global

Ok, in my test example, the mdb is called BypassShiftKey.mdb.  Change the name to be the same as your app.  Change the path to the location of the app

********************************************************************************************************************
**********Make a Backup before you implement.  A error can lock it up and you may NEVER get it.  *************************************
********************************************************************************************************************


To make it work,in the  of the form that opens when your application starts, place a call to CheckDisableShiftKey

Private Sub Form_Load()
    Call CheckDisableShiftKey
End Sub

This immediately runs the code.  If the app is opened without the special shortcut, the user cannot get to the db window, not matter what.  You nned to make no changes to the startup options, in fact you can set everything from the code.

********************************************************************************************************************
**********Make a Backup before you implement.  A error can lock it up and you may NEVER get it.  *************************************
********************************************************************************************************************
Avatar of jwah

ASKER

Thanks and backup noted. BUT still nogo but think I have found something the missign ELSE. You gave me :-


If strCmdLine = "IntAdmin" Then
       ChangeProperty "StartupShowDBWindow", dbBoolean, True
       ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
       ChangeProperty "AllowFullMenus", dbBoolean, True
       ChangeProperty "AllowBreakIntoCode", dbBoolean, True
       ChangeProperty "AllowSpecialKeys", dbBoolean, True
       ChangeProperty "AllowBypassKey", dbBoolean, True
       ChangeProperty "AllowShortCutMenus", dbBoolean, True
       retval = Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" & Chr$(34) & " " & Chr$(34) & db.Name & Chr$(34), vbMaximizedFocus)
       'Debug.Print db.Name
       'MsgBox db.Name
       ChangeProperty "StartupShowDBWindow", dbBoolean, False
       ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
       ChangeProperty "AllowFullMenus", dbBoolean, False
       ChangeProperty "AllowBreakIntoCode", dbBoolean, False
       ChangeProperty "AllowSpecialKeys", dbBoolean, False
       ChangeProperty "AllowBypassKey", dbBoolean, False
       ChangeProperty "AllowShortCutMenus", dbBoolean, False
       DoCmd.Quit
   End If

Please advise.
Avatar of jwah

ASKER

Also........................

1. What is the DoCmd.Quit do ? as I want to open the FORM specified in Startup... named MAINMENU.


many thanks jwah
Avatar of jwah

ASKER

UPDATE FROM more Testing...... with the ELSE added. I think I am getting closer.

It disables OK but upon running it again with the IntAdmin from the shortcut - it goes around and around enaling and disabling things (I get both messages) and the FORM "MAINMENU" never opens!


Here is my code in basMAIN

Function CheckDisableShiftKey()
Dim retval As Variant
Dim strCmdLine As String

   Set db = CurrentDb()
   strCmdLine = Command()
   'MsgBox strCmdLine
   
   If strCmdLine = "IntAdmin" Then
       MsgBox "Enabling"
       ChangeProperty "StartupShowDBWindow", dbBoolean, True
       ChangeProperty "AllowBuiltinToolbars", dbBoolean, True
       ChangeProperty "AllowFullMenus", dbBoolean, True
       ChangeProperty "AllowBreakIntoCode", dbBoolean, True
       ChangeProperty "AllowSpecialKeys", dbBoolean, True
       ChangeProperty "AllowBypassKey", dbBoolean, True
       ChangeProperty "AllowShortCutMenus", dbBoolean, True
       retval = Shell(Chr$(34) & "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" & Chr$(34) & " " & Chr$(34) & db.Name & Chr$(34), vbMaximizedFocus)
       'Debug.Print db.Name
       'MsgBox db.Name
    Else
       MsgBox "Disabling DB access"
       ChangeProperty "StartupShowDBWindow", dbBoolean, False
       ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
       ChangeProperty "AllowFullMenus", dbBoolean, False
       ChangeProperty "AllowBreakIntoCode", dbBoolean, False
       ChangeProperty "AllowSpecialKeys", dbBoolean, False
       ChangeProperty "AllowBypassKey", dbBoolean, False
       ChangeProperty "AllowShortCutMenus", dbBoolean, False
       DoCmd.Quit
   
   End If
   
End Function

-----------------------

also I have added

Call CheckDisableShiftKey          in the FORM LOAD function, I also tried omitting the "Call".

Any ideas?


ASKER CERTIFIED SOLUTION
Avatar of 1William
1William

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had a feelling you'd get it.  :)