Disable Shiftkey Round Two

Access 97:

I found the following example in the Access Help File “AllowBypassKey Property”

I can’t figure out how to use this and/or apply the following example to disable my Shiftkey.
Can anyone please explain how to properly use this example.


The following example shows a procedure named SetStartupProperties that passes the name of the property to be set, its data type, and its desired setting. The general purpose procedure ChangeProperty attempts to set the startup property and, if the property isn't found, uses the CreateProperty method to append it to the Properties collection of the Database object. This is necessary because these properties don't appear in the Properties collection until they've been set or changed at least once.

Sub SetStartupProperties()
ChangeProperty "StartupForm", dbText, "Customers"
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "StartupShowStatusBar", dbBoolean, False
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, True
ChangeProperty "AllowBreakIntoCode", dbBoolean, False
ChangeProperty "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

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


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A brief explanation on what is happening here, and then the steps to use it effectively.

Under Tools | Startup Access gives you a chance to disable the shift key (and other special keys (like F11 to show the database window) among other options. As you can see, though, these are "startup options." That means that they don't take effect immediately. You have to close your database, open it once without preventing your startup options, and then the shift-key bypass will be disabled.

The code above is for automating this process back and forth. Copy the two functions into a new module in your application and then call them by using

Call SetStartupProperties

As an example for you, in my apps I've used this kind of check as part of the AutoExec macro or my main form's Load event:

If Environ$("UserName") = "dbrewer" then
   Call SetStartupProperties(True)
   Call SetStartupProperties(false)
end if

with a modified SetStartupProperties that would look like:

Sub SetStartupProperties(fAdmin as boolean)
   ChangeProperty "AllowBuiltinToolbars", dbBoolean, fAdmin
   ChangeProperty "AllowFullMenus", dbBoolean, fAdmin
   ChangeProperty "AllowBreakIntoCode", dbBoolean, fAdmin
   ChangeProperty "AllowSpecialKeys", dbBoolean, fAdmin
   ChangeProperty "AllowBypassKey", dbBoolean, fAdmin
End Sub

Now, if other users log in, Startup properties will be false, meaning they won't be able to use special keys, etc. But when I open the database (the first time) it will reset those startup options. I then simply exit the database and start up again, using my Shift key.

Hope that helps some . . .


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DWBAuthor Commented:
Okay, call me stupid, I have the module, but I still can’t get this. How do I call it?

I’ll provide a little background on how I set this up.

I’ve tried several times to create a secure database through Accesses User Group method etc… and have failed miserably. So I currently use the following code in an introductory (Splash Screen) this however is were the Shift Key issue comes into play.

Intro Screen Called “zfrmIntro” which I set for the display form in the Startup Options.

************* Code Starts ****************

' ACTION - Prompt's the user for a password when they open the
' Main Menu form . If the correct password is entered, the
' form is opened. If Not Close and Exit the database.

Private Sub Form_Open(Cancel As Integer)
Dim strPassword As String

strPassword = InputBox("This form is password-protected. Please enter the correct password below to access the form.", "Password Required")

If strPassword <> "PlacePasswordHere" Then
MsgBox "That is an incorrect password: access has been denied.", vbInformation, "Access Denied"
DoCmd.Quit acExit

End If

End Sub

************* Code Ends ****************
well, where in that code do you want it? Could you explain why you want to use the SetStartupProperty code at all? Do you need some users with the ability to get into the database window, etc., and others don't? If so, then the explanation and example I gave above would seem to suit your needs well.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Sorry, I'm a little late.  I posted a comment to this question (very similar to brewdog's, but not as thorough) on the old question.  Take a look at the PAQ FYI.  brewdog's right on.

good luck as usual...

The best way to do this is to create another DB and put the code there.  You can either run this by a macro or from the debug window.  We use this code to disable the bypass keys for all our outgoing apps.


Function DisableBypass() As Boolean
  ' Comments   :  Disable the bypass key (shift) the distribution mdb files
  ' --------------------------------------------------------

  Dim wrkWksMdb As Workspace
  Dim dbsMdb As Database
  Dim strLastFunction As String
  Dim strCurrentUser As String
  strCurrentUser = DBEngine.Workspaces(0).UserName
  If MsgBox("Do you really want to DISABLE bypass keys (Shift)?", _
                vbYesNo + vbExclamation + vbDefaultButton2 + vbSystemModal) = vbNo Then
    Exit Function
  End If

  Set wrkWksMdb = CreateWorkspace("wrkWksMdb", strCurrentUser, "")

  Set dbsMdb = wrkWksMdb.OpenDatabase(Path & DBName, True)  '  Put in the valid path and name for the DB

  If DisableByPassKey(dbsMdb) Then
      MsgBox "Bypass key (shift) DISABLED!", vbOKOnly + vbExclamation + vbSystemModal
  End If

  Set dbsMdb = Nothing
  Set wrkWksMdb = Nothing
End Function

Function DisableByPassKey(dbsWork As Database) As Boolean
  ' Comments   : Disable the ability to hold down the shift key when running the database.
  ' --------------------------------------------------------

  On Error GoTo Proc_Err

  Dim prpThis As Property

  With dbsWork
    Set prpThis = .CreateProperty("ALLOWBYPASSKEY", dbBoolean, False)
    .Properties.Delete "ALLOWBYPASSKEY"
    .Properties.Append prpThis
  End With

  Set prpThis = Nothing
  DisableByPassKey = True

  Exit Function

  Select Case Err.Number
    Case 3265         ' Item not found in this collection.
       ' ok. it just could not delete the "ALLOWBYPASSKEY" property because it had
       ' not yet been created. No problem. Just itnore it.
    Case Else
       ' real problem so choke.
       DisableByPassKey = False
       Application.RunCommand acCmdDebugWindow ' force the debug window open
       Debug.Print "Error in DisableByPassKey()", Err.Number, Err.Description
  End Select
  Resume Next

End Function

DWBAuthor Commented:
I must apologize for the late response, however, unfortunately every now and again I actually have to perform my real job and make an appearance once or twice at work.

I played around with brewdogs response a bit last night, and I finally got it together. I truly appreciate all the responses, guidance, suggestions, and most importantly everyone’s patience with the novice who tends to bite off more then he can normally chew, thanks for not letting me choke.

If anyone requires any miscellaneous paraphernalia from the Canadian Forces, I’ll try my best to provide, just give me a shout at "dbrydon@webhart.net".

Hope one and all, have a Safe and Rewarding New Year.


Great, Dave. Glad I could help out a little.

And don't worry about biting off more than you can chew: I think it's expected of programmers now. :o)
Hey people, I tried to implement the code brewdog first talked about...in the access 2000 help... I put it in a module, called it, it doesnt crap out or show an error, but it simply wont work, i cant get any of the properties to change, is there anything else you have to do to make this work?? Any additional libraries to call to or anything?? Thanks guys!


These fixes were done for Access 97.  I don't think that they apply to Access 2000.  I haven't worked with Access in a while but I think that there are attributes you can set directly in Access 2k that will do this for you.


The actual code is taken from the access 2000 help. However, ive tried everything I can think of.... seperate modules, in the open form event, blah blah... it will not change the properties... it doesnt crap out, or cause any errors, in fact it passes right through the code....but nothing happens...really weird....


I'm busy on some projects at the moment but send me the code you are trying to use and I'll take a look and see what I think is happening.  You should know that any code you take from Access 2000 help files may not actually work.  I've seen this over and over.  However, code snippets that Microsoft supplies are good starting points to write your own code.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.