Link to home
Start Free TrialLog in
Avatar of rainbowbear
rainbowbear

asked on

How To Disable Shift Key Bypass In Access 97

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

'=============================
Avatar of GOLLEM
GOLLEM

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  
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.
ASKER CERTIFIED SOLUTION
Avatar of mgrattan
mgrattan

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 rainbowbear

ASKER

Adjusted points from 100 to 200
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?  ;-)
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.
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.
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.
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.
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.
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
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
>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!