Solved

How To Disable Shift Key Bypass In Access 97

Posted on 2000-03-31
13
643 Views
Last Modified: 2012-06-21
I found the following code in the answer to another question on the same subject, but I don't know what to do with it.  I tried creating a new module and pasting the code into it, but I was not able to run the module.

Please give me step by step instructions if you can.

Thanks

'========   THE CODE FOLLOWS   ========

Function faq_DisableShiftKeyBypass() As Boolean
      'The next time the database is opened
      ' after this function has been run,
      ' the autoexec macro will not be bypassed,
      ' even if the shift key is pressed.
      On Error GoTo errDisableShift
      Dim db As Database
      Dim prop As Property
      Const conPropNotFound = 3270
      Set db = CurrentDb()
      db.Properties("AllowByPassKey") = True
      faq_DisableShiftKeyBypass = True
exitDisableShift:
      Exit Function
errDisableShift:
      'The AllowBypassKey property is a user-defined
      ' property of the database that must be created
      ' before it can be set. This error code will execute
      ' the first time this function is run in a database.
      If Err = conPropNotFound Then
      Set prop = db.CreateProperty("AllowByPassKey", _
         dbBoolean, False)
         db.Properties.Append prop
         Resume Next
      Else
         MsgBox "Function DisableShiftKeyBypass did" & _
               " not complete successfully."
         faq_DisableShiftKeyBypass = False
         GoTo exitDisableShift
      End If
   End Function

'=============================
0
Comment
Question by:rainbowbear
13 Comments
 

Expert Comment

by:GOLLEM
ID: 2675778
rainbowbear,

Look at the access help file on the AllowBypassKey property of the database object.

look at the example to see how to create the property.

This should help :)

regards,

       Michiel  
0
 
LVL 2

Expert Comment

by:AlexJ030200
ID: 2675865
You should call faq_DisableShiftKeyBypass() at least once in your database.

I normally put this kind of code in the open actions of a form that you always open.

You could also simply execute it with the debugger although I've never tried it.

Hope this helps.
0
 
LVL 14

Accepted Solution

by:
mgrattan earned 200 total points
ID: 2676493
Here's a modified version of the above function that allows you to change the property at will via the Immediate Window.  Just pass a True if you want the Shift Key enabled or a False if you want it disabled.  

Function SetBypassKey(bState As Boolean)
      On Error GoTo SetByPass_EH
      Dim db As Database
      Dim prop As Property
      Const conPropNotFound = 3270
      Set db = CurrentDb()
      db.Properties("AllowByPassKey") = bState
SetBypass_Exit:
      Exit Function
SetByPass_EH:
      If Err = conPropNotFound Then
      Set prop = db.CreateProperty("AllowByPassKey", _
         dbBoolean, False)
         db.Properties.Append prop
         Resume Next
      Else
         MsgBox "Function SetBypassKey did" & _
               " not complete successfully."
         GoTo SetBypass_Exit
      End If
End Function


Press CTRL-G to open the Immediate Window.  Type the following:

?SetBypassKey(True)

and press Enter to run the function to enable shift key bypass.  Use False to disable shift key bypass.  As long as you have your database's Startup options set for allowing Access Special Keys you will always be able to turn this property on and off through the Immediate Window by pressing CTRL-G and running the function.

Mike.
0
 

Author Comment

by:rainbowbear
ID: 2676550
Adjusted points from 100 to 200
0
 

Author Comment

by:rainbowbear
ID: 2676551
Thanks for the suggestions.

I'm sorry if my question made it sound like I know more than I do.  

I am a rookie and I have very little experience with code.

In addition to the code itself, I need step by step help with just how to use it.

For example:

Do I copy the code into a module?  If so, how do I run the code?

Do I copy the code into the Immediate Window?  If so, how do I run the code from there?  How do I save the code for future use?

Since this database is used by multiple users, if I use the method and code suggested by mgrattan that allows the property to be turned on and off, can any knowledgable user do that, too?

Is there a good book that answers these questions so I can quit bugging the experts?  ;-)
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 2676823
Create a new module and copy the code into it.  Save the module.  Press CTRL-G to open the Immediate Windows.  Enter the following into the Immediate Window:

?SetBypassKey(True)

and press Enter.  This will allow the shift key to bypass the AutoExec macro or any other events that are executed through the Startup process.  Using False instead of True will lock the shift key.

Once you have saved the code into a module it will stay there for future use....you can also copy it to modules in other databases for use on other applications.

Yes, a knowledgeable user (VERY knowledgeable) could possibly figure this out.  You could give the procedure a name that is harder to figure out.  That way, only you will know how to run it.  For example, instead of calling the procedure SetBypassKey you could call it something bizarre like BullwinkleLovesAerosmith.  Now, who would figure that out?

Mike.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 14

Expert Comment

by:mgrattan
ID: 2676825
As far as books go, my favorite is the Access 97 Developers Handbook by Letwin/Getz.  I'm pretty sure it's available on amazon.com

Mike.
0
 

Author Comment

by:rainbowbear
ID: 2676964
To mgrattan:

I hope I didn't do anything wrong, but it still didn't work.

I created a new database to test the code.  There is nothing in the database except the new module that I created per your instructions.

I opened the Immediate Window and entered the information you suggested.  I got the following Error Message:





===============================

Compile error:

Expected variable or procedure, not module.

===============================





After I got the Error Message, I checked the "Help" for the error and it reads as follows:





***********************************

There is no variable or procedure by this name in the current scope, but there is a module by this name. This error has the following cause and solution:

The name of a module is used as a variable or procedure.

Check the spelling of the variable or procedure name, and make sure the name you want to refer to isn't private to another module. A module name can be a qualifier, but can't stand alone.

For additional information, select the item in question and press F1.

***********************************





I also checked the "Help" for AllowBypassKey which includes the following statement:

"To set the AllowBypassKey property by using a macro or Visual Basic, you must create the property by using the CreateProperty method and append it to the Properties collection of the Database object."

I checked the "Help" for CreateProperty, but it's way over my head.

Do I need to do something with the CreateProperty method, and if so, how?  (remember, I'm an idiot).

And, thanks for the info on the book.
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 2677028
The code will automatically create the AllowBypassKey property if it doesn't already exist.  If you are receiving such an error message then perhaps something else is wrong.

Let's assume that you created a new module, copied the function into the module and saved the module as modBypassKey (doesn't matter what you call the module).  Now, open the module by double-clicking it in the Modules tab of the Database Container.  You should see your function--press the toolbar button to compile the module (the button looks like a stack of papers with a blue down-arrow) or you can select Debug,Compile Loaded Modules from the menu.  Do you get an error?  If so, select Tools, References from the menu and make sure you have a check mark next to the reference called Microsoft DAO 3.5 Reference Library.  This reference is required in order to run any DAO code (which this module uses when declaring a variable for the Database object).  If the reference is not available then you did not install the Data Access Objects when you installed Access.  You will need to re-install Access and make sure this option is selected.  

Still getting the error?  Open the code module and click with your left mouse button in the gray border to the left side of the line that says "db.Properties("AllowByPassKey") = bState".  This will create a break point in your code for trouble-shooting and you should now see a red highlight on that line.  Now open the Immediate Window by pressing CTRL-G and run the function by typing the following:

?SetbypassKey(True)

and press Enter (by the way, as soon as you press the left parentheses when typing the function Access should drop-down a list of two options, True and False--if it does not, then something is wrong with the way the function was copied into the module).

The code should stop at your break point.  If you don't have an error message yet, go ahead and step through the code one line at a time by pressing the F8 key.  Make note of which line in the code causes the error message and post it here for me to look at.

Mike.
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 2677093
The code will automatically create the AllowBypassKey property if it doesn't already exist.  If you are receiving such an error message then perhaps something else is wrong.

Let's assume that you created a new module, copied the function into the module and saved the module as modBypassKey (doesn't matter what you call the module).  Now, open the module by double-clicking it in the Modules tab of the Database Container.  You should see your function--press the toolbar button to compile the module (the button looks like a stack of papers with a blue down-arrow) or you can select Debug,Compile Loaded Modules from the menu.  Do you get an error?  If so, select Tools, References from the menu and make sure you have a check mark next to the reference called Microsoft DAO 3.5 Reference Library.  This reference is required in order to run any DAO code (which this module uses when declaring a variable for the Database object).  If the reference is not available then you did not install the Data Access Objects when you installed Access.  You will need to re-install Access and make sure this option is selected.  

Still getting the error?  Open the code module and click with your left mouse button in the gray border to the left side of the line that says "db.Properties("AllowByPassKey") = bState".  This will create a break point in your code for trouble-shooting and you should now see a red highlight on that line.  Now open the Immediate Window by pressing CTRL-G and run the function by typing the following:

?SetbypassKey(True)

and press Enter (by the way, as soon as you press the left parentheses when typing the function Access should drop-down a list of two options, True and False--if it does not, then something is wrong with the way the function was copied into the module).

The code should stop at your break point.  If you don't have an error message yet, go ahead and step through the code one line at a time by pressing the F8 key.  Make note of which line in the code causes the error message and post it here for me to look at.

Mike.
0
 

Author Comment

by:rainbowbear
ID: 2682524
to mgrattan:

Mike,

I was out of town for the weekend so I haven't had time to try your new suggestions.  Hopefully, I will be able to get to it Tuesday.

Thanks,
George
0
 

Author Comment

by:rainbowbear
ID: 2683929
To mgrattan:

Thanks Mike,

It works great.  I don't know if it should make a difference, but the first time I tried it (when I got the first Error Message), I did not compile the code.  Could that be why it was not working?

Thanks again for your help,
George
0
 
LVL 14

Expert Comment

by:mgrattan
ID: 2684213
>I don't know if it should make a difference, but the first time I tried >it (when I got the first Error Message), I did not compile the code.  >Could that be why it was not working?

Yes, especially if you called the module the same thing as the function.

Thanks for the points, glad I could help!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now