Link to home
Start Free TrialLog in
Avatar of hhheng
hhheng

asked on

Disable SHIFT key

I would like a sample code on how to disable the SHIFT key to prevent user from bypassing the startup macro.

thanks
Avatar of berg1375
berg1375

Paste this into a module and run it:

Sub SetStartupProperties()
"AllowSpecialKeys", dbBoolean, True
      ChangeProperty "AllowBypassKey", dbBoolean, True

End Sub

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

      Set dbs = CurrentDb
      On Error GoTo Change_Err
      dbs.Properties(strPropName) = varPropValue
      ChangeProperty = True

Change_Bye:
      Exit Function

Change_Err:
      If Err = conPropNotFoundError Then      ' Property not found.
            Set prp = dbs.CreateProperty(strPropName, _

varPropType, varPropValue)
            dbs.Properties.Append prp
            Resume Next
      Else
            ' Unknown error.
            ChangeProperty = False
            Resume Change_Bye
      End If
End Function
Hmmm.  If you disable the shift, how are you going to get into it?
Disabling the shift key just means the user will not be able to bypass the startup features by holding down the shift key and opening the database. They just want to keep the users in line   :)
<<If you disable the shift, how are you going to get into it? >>

You can use a slightly modified version of the function berg1375 posted.  This version takes a boolean variable (True or False) that can be used to either enable or disable the Shift key bypass.  You can initiate the function from the debug window by pressing CTRL-G as long as you have not deactivated the Access Special Keys in the database's Startup options.

Function BackDoor(rbFlag As Boolean) As Integer
On Error GoTo BackDoor_Error

'This function creates a new database property
'which can prevent a user from using from using
'the shift key to bypass the startup options
'
'The function must be run at least once during
'development. Run it from the Debug window
'using the appropriate argument:
'  ?BackDoor(True)  'Enables the Shift Key bypass
'  ?BackDoor(False) 'Disables the Shift Key bypass
'-------------------------------------------

Dim db As Database
Set db = CurrentDb
db.Properties!AllowBypassKey = rbFlag

BackDoor_Exit:
   Exit Function
   
BackDoor_Error:
   If Err = 3270 Then
      'AllowBybassKey property does not exist
      db.Properties.Append _
         db.CreateProperty("AllowBypassKey", _
         dbBoolean, rbFlag)
      Resume Next
   Else
      'Some other error
      MsgBox "Unexpected error: " & Error$ & " (" & Err & ")"
      Resume BackDoor_Exit
   End If

End Function

BTW, you can still get into the database window from the debug window by using the DoCmd.SelectObject method.  Just don't let your user's know this.  If they are *very* sophisticated users you will want to take further steps to lock down your database, such as compiling it to an MDE.
Avatar of Jim Dettman (EE MVE)
FWIW did you know that you can re-enable the bypass from another MDB?  So even if you disabled control G, you still can get by it.

Jim.
Yep, you can actually re-enable the bypass from *any* automation client by connecting to the host database and setting it up as an automation server.  However, you still need to know the name of the function to call and how to call it.  Therefore, if you give it a name the users are not likely to guess you will have a pretty effective solution for locking the shift-key bypass.
Avatar of hhheng

ASKER

Hello berg1375,

You said "Paste this into a module and run it"..... nothing happen.Can you explain further on how and where to append and run the "Disable SHIFT" module.

thanks
hhenq,

In the On Open of your first form :

Call SetStartupProperties

WP
hhheng-

Nothing will happen on the display when you run the module. You only have to run the module once. It does not need to be run in the OnOpne of any form, just once and they are set until you want to change the properties.

Just open a "new" module. Paste the code inside of it. Move your cursor to the line "AllowSpecialKeys", dbBoolean, True and hit the run button. In all actuality you should delete or comment out the "AllowSpecialKeys" line of code. It is not essential for you to run that line of code. Once you have run that code, close the DB, and try to reopen it using the shift key.

HTH
berg
I tried this code as well and even stepped through the process and nothing worked.  It didn't give any errors so I assume it worked the way you wanted it to.  However, when I open explorer and held the shift key down and then double clicked on my access DB it opens by-passing the startup screen.  I am using Access 95 so that could be the problem on a windows 95 machine.  The only reason I am posting this message is because it seems like hhheng was having problems as well and I did not want him to think he was alone.

M!
In the code above from berg1375, to disable the shift shouldn't the boolean switch be false?  I use the following in my start-up protection module

    ChangeProperty "AllowSpecialKeys", dbBoolean, False
    ChangeProperty "AllowBypassKey", dbBoolean, False

And the keys are disabled.
Man, I am an idiot   :(

Thanks for noticing Allen, I completely over looked that. You are correct.
You are definetly not an idiot, when I first looked I wondered if my code actually worked so I went back and checked before I said anything.  Made me look.  :-).
Now that makes a world of difference.  Thought I was losing it for a few minutes.  berq1375 your are one of last people in this forum I would ever call an idiot.  Everyone needs a little help from there friends and I consider everyone in this forum to be my friend.  Gee I have a lot of friends.

Cya,

M!
ASKER CERTIFIED SOLUTION
Avatar of berg1375
berg1375

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
Avatar of hhheng

ASKER

Hi berg1375

After Allen's input, your Disable Shift code is now functioning. I'm very sorry to hear that you have spent so much time to do this coding.Thanks a lot

heng

hhheng-

Just to clarify, the code I posted is not my doing. This code comes from the Access online help file. I use it in all of my databases though.

I am glad that you finally got it working   :)

berg
What is the Access online help file?  You talkin about the MSDN help or is there another place I am missing?
Just the help file that comes with MSAccess. You would not believe how much information, and source code there is in there. Between the Online file, and the Microsoft knowledge base, you can pretty much figure out anything   :)
Here is a VB function that set up a number of start-up parameters, including disabling the shift key.
Delete the features you do not need.

Only run this function on a copy of your databse as you will be unable to access the Database window afterwards.

In my applicication, I have added code tocheck the application file name is my compile mde version.

Alistair

Here is a VB function that set up a number of start-up parameters, including disabling the shift key.
Delete the features you do not need.

Only run this function on a copy of your databse as you will be unable to access the Database window afterwards.

In my applicication, I have added code tocheck the application file name is my compile mde version.

Alistair

Code below:


Function SetStartupProperties()
On Error GoTo SetStartupProperties_Err

Dim db As Database


Set db = CurrentDb


    ChangeProperty "StartupForm", dbText, "Splash Screen"
    ChangeProperty "StartupShowDBWindow", dbBoolean, False
    ChangeProperty "StartupShowStatusBar", dbBoolean, True
    ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
    ChangeProperty "AllowFullMenus", dbBoolean, False
    ChangeProperty "AllowBreakIntoCode", dbBoolean, False
    ChangeProperty "AllowSpecialKeys", dbBoolean, False
    ChangeProperty "AllowBypassKey", dbBoolean, False
    Application.RefreshTitleBar

   
       
    Exit Function
   
SetStartupProperties_Err:
    MsgBox Error$
    Exit Function
   
End Function
AWScobie,

It is customary to propose Comments in the Access topic area of Experts Exchange (and most other topic areas as well).  Besides, the "Answer" you proposed has already been discussed in the Comments previously posted in this question.  Please withdraw your Answer so that it will be converted to a Comment.  The question-asker has the option to accept any Comment as the Answer.

Thank you.