• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

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


  • 3
  • 3
  • 2
  • +2
1 Solution
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 . . .

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.
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now