AllowBypassKey

G

Guest

can any one tell me step by step way how to use this property to stop users open the database by pressing shift key, I have tryed different codes but i dont know where to put that code and where is the immidiate window, so pls tell me step by step how to do this. thanks
 
J

Joan Wild

Copy your database.

Make sure you are in the main database window. Click the "modules" tab, then
select "new." Alternatively, you can open an existing module if you have
one.

Copy/paste the following function into it. Save the module giving it some
name other than DisableShiftKeyBypass.

**start**

Function DisableShiftKeyBypass() As Boolean
On Error GoTo errDisableShift

Dim db As Database
Dim prop As Property

Set db = CurrentDb()

On Error Resume Next
db.Properties.Delete "AllowByPassKey"
On Error GoTo errDisableShift

Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)
db.Properties.Append prop
DisableShiftKeyBypass = True

exitDisableShift:
Set prop = Nothing
Set db = Nothing
Exit Function

errDisableShift:
MsgBox "Function DisableShiftKeyBypass did not complete successfully."
DisableShiftKeyBypass = False
Resume exitDisableShift

End Function

***end***

Click on Debug, Compile, and then close the module saving it.

At the database window, hit Ctrl-G which will open the debug window.

Type DisableShiftKeyBypass() and hit enter.

The next time you open the db, the shift will be disabled.

You only need to run the sub once to set the property and then it is set.
It isn't something you would run repeatedly as it isn't necessary.

You can go back to that copy you made in step 1 (which you'll keep in a safe
place) when you want to make changes, or you can use another database to
set the prop back on this database.

Or you could use Albert's utility to set it on/off. Look for By Pass Shift
Key Code at
http://www.attcanada.net/~kallal.msn/msaccess/msaccess.html

--
Joan Wild
Microsoft Access MVP

Sherry said:
can any one tell me step by step way how to use this property to stop
users open the database by pressing shift key, I have tryed different codes
but i dont know where to put that code and where is the immidiate window, so
pls tell me step by step how to do this. thanks
 
G

Guest

Thanks Joan, but if I disable the shift key with your method how can I use the shift key for maintainance purposes, as for security I am using windows login and password that has checked against my security table where I gave the access rights to different users to different forms, also from the startup I disable all the menus and the shortcut keys. Is there any way that I can enable shift key when it is required. As you suggested to have a separate copy for the database for maintanance but then what will happen to existing data. For some reason Albert's utility is not working it gives me an error in the code. so any other options!!!
 
J

Joan Wild

Sherry said:
Thanks Joan, but if I disable the shift key with your method how can I use
the shift key for maintainance purposes, as for security I am using windows
login and password that has checked against my security table where I gave
the access rights to different users to different forms, also from the
startup I disable all the menus and the shortcut keys. Is there any way that
I can enable shift key when it is required. As you suggested to have a
separate copy for the database for maintanance but then what will happen to
existing data. For some reason Albert's utility is not working it gives me
an error in the code. so any other options!!!

It is very rare that I ever need to set it back. I usually create a mde;
open the mde and set startup options, disable the shiftkey and distribute.

If I need to change something, I'm doing that in the original mdb where the
shift key isn't disabled.

As for existing data, you should split your database - Have the backend on
the server and give each user a copy of the frontend linked to the backend
tables. Once you have made changes you'd distribute the new frontend to
your users. You shouldn't have everyone using the same copy of the frontend
as you'll likely corrupt the database.

But you can, if you need to, set the shiftkey back from another mdb.

Use the same function with a few modifications:

You'd need to add
Dim wrk As Workspace
then
Set wrk = DBEngine.Workspaces(0)
and change the Set db statement to
Set db = wrk.OpenDatabase("path to mdb")

Then change this line
Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)
to
Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, True, True)
 
A

Aaron

-----Original Message-----


(e-mail address removed)... method how can I use
the shift key for maintainance purposes, as for security I am using windows
login and password that has checked against my security table where I gave
the access rights to different users to different forms, also from the
startup I disable all the menus and the shortcut keys. Is there any way that
I can enable shift key when it is required. As you suggested to have a
separate copy for the database for maintanance but then what will happen to
existing data. For some reason Albert's utility is not working it gives me
an error in the code. so any other options!!!

It is very rare that I ever need to set it back. I usually create a mde;
open the mde and set startup options, disable the shiftkey and distribute.

If I need to change something, I'm doing that in the original mdb where the
shift key isn't disabled.

As for existing data, you should split your database - Have the backend on
the server and give each user a copy of the frontend linked to the backend
tables. Once you have made changes you'd distribute the new frontend to
your users. You shouldn't have everyone using the same copy of the frontend
as you'll likely corrupt the database.

But you can, if you need to, set the shiftkey back from another mdb.

Use the same function with a few modifications:

You'd need to add
Dim wrk As Workspace
then
Set wrk = DBEngine.Workspaces(0)
and change the Set db statement to
Set db = wrk.OpenDatabase("path to mdb")

Then change this line
Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)
to
Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, True, True)

--
Joan Wild
Microsoft Access MVP


.
I have been looking for a solution myself...It seems
that you can only reset the startup properties on exit.
So If an administrator logs in, I set them to reset the
properties to True when an admin exits. The admin has to
log in twice to get the properties. BUT...you CAN't
forget to turn everything off from the MENU ONLY
(Tools/Startup) if you are going to distribute the front
end. Otherwise, if the admin was the last person to
exit, the other users will have full access.

Here is my code (call this procedure when user exits the
database):

Sub SetStartupProperties()
'(TorF As Boolean)
'Const DB_Text As Long = 10
Const DB_Boolean As Long = 1

ChangeProperty "StartupForm", DB_Text, "F_MainForm"
ChangeProperty "StartupShowDBWindow", DB_Boolean, False

If CurrentUserInGroup("Admins") = True Then
'Set these to True for Admins
ChangeProperty "StartupShowStatusBar", DB_Boolean,
True
ChangeProperty "AllowBuiltinToolbars", DB_Boolean,
True
ChangeProperty "AllowFullMenus", DB_Boolean, True
ChangeProperty "AllowBreakIntoCode", DB_Boolean, True
'(F11 Key)
ChangeProperty "AllowSpecialKeys", DB_Boolean, True
'Key that allows you to bypass AutoExec macro (SHIFT
KEY)
ChangeProperty "AllowBypassKey", DB_Boolean, True
Else
'Set these to False for everyone else
ChangeProperty "StartupShowStatusBar", DB_Boolean,
False
ChangeProperty "AllowBuiltinToolbars", DB_Boolean,
False
ChangeProperty "AllowFullMenus", DB_Boolean, False
ChangeProperty "AllowBreakIntoCode", DB_Boolean, False
'(F11 Key)
ChangeProperty "AllowSpecialKeys", DB_Boolean, False
'Key that allows you to bypass AutoExec macro (SHIFT
KEY)
ChangeProperty "AllowBypassKey", DB_Boolean, False
End If

End Sub

'I got this code from the help files:
Function ChangeProperty(strPropName As String,
varPropType As Variant, varPropValue As Variant) As
Integer
Dim dbs As Object, prp As Variant
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
 
G

Guest

I have tried this, copied the code and followed instructions. I get error
message:
"Compile Error:
Expected:="

Any further assistance?
Thanks
 
D

Douglas J. Steele

You've already got a couple of other suggestions that require answers from
you. I just thought I'd point out that

Dim db As Database
Dim prop As Property

would be safer as

Dim db As Database
Dim prop As DAO.Property
 
G

Guest

Thanks for the responses. It seems that with limited knowledge I am
struggling to pose the right questions. I named my module "key". I cannot see
any indication of the line the error is occuring on - I get a message with
the error in my original post.
I tried changing:
Dim db As Database
Dim prop As DAO.Property

and still getting the same error.

Thanks again.
 
D

Douglas J. Steele

Within the VB Editor, go to the Debug menu and choose to Compile (the first
option). That should highlight the specific line that's causing problems.
 
G

Guest

Thanks, I did this but no errors were highlighted. I did some experimenting
and found the problem. The instructions were that I should type
DisableShiftKeyBypass() and hit enter. I changed this to
DisableShiftKeyBypass -without ()- and it worked when I hit enter and then
re-opened the db.

Thanks all for your help.
 
G

Guest

Perhaps one last look for comments on what I am doing. I am based in
Johannesburg and send out db's to clients around the country. It is
impractical to make changes on site, (travel etc) but I need to protect the
design while being able to makie changes. My plan is to create back-ups (for
my use), split, create MDE of the FE and diasbale shiftkey for distribution.
Changes will then be made to my version of the FE which will be distributed
as MDE with the shift key disabled. Is thi the best option without user level
security?

I understand from reading on this site that someone with knowhow can enable
the shiftkey, but this is not a concern where I am operating.

Thanks again
 
T

TC

It depends what you mean by "protect the design". If you mean, to stop
the user changing the datbase schema, then what you propose is not
enough. The user can open the back-end database & change the schema to
his heart's content. But if you mean, to stop the user viewing or
changing your program code, then, making the front end an MDE is a fine
& easy way to do that. Really, no-one could say much more, unless you
clearly defined what user actions you need to prevent.

HTH,
TC
 
G

Guest

Hi,

Ive followed your instruction but cannot get thru Expected = error msg pop
up..

any idea?
 
G

Guest

I have been having the same problem setting this up. However when I
debug/compile it doesn't like:
Dim db as Database
I get Compile Error - User-defined type not defined.
How do I fix this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top