Shift Key

  • Thread starter Thread starter Tom5
  • Start date Start date
T

Tom5

I have been trying to finish off my database. I need to disable the shift key
and then have an admin button in which I can enter a password in, to
re-enable it. However I have come to a point at which I am stuck. I am using
the following script to run my command:

Option Compare Database
Option Explicit

Public Function SetProperties(strPropName As String, _
varPropType As Variant, varPropValue As Variant) As Integer

On Error GoTo Err_SetProperties

Dim db As DAO.Database, prp As DAO.Property

Set db = CurrentDb
db.Properties(strPropName) = varPropValue
SetProperties = True
Set db = Nothing

Exit_SetProperties:
Exit Function

Err_SetProperties:
If Err = 3270 Then 'Property not found
Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
db.Properties.Append prp
Resume Next
Else
SetProperties = False
MsgBox "SetProperties", Err.Number, Err.Description
Resume Exit_SetProperties
End If
End Function
'***************** Code End ***************Once you have created the module,
then you will need to attach the following code to a command button (or
label, graphic etc.):

'***************** Code Start ***************
'Assign this to the OnClick event of a command button (or double-click event
'of a label or graphic) named "bDisableBypassKey"
'Change the "TypeYourBypassPasswordHere" default password to your password

Private Sub bDisableBypassKey_Click()
On Error GoTo Err_bDisableBypassKey_Click
'This ensures the user is the programmer needing to disable the Bypass Key
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
"Please key the programmer's password to enable the Bypass Key."
strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
If strInput = "TypeYourBypassPasswordHere" Then
SetProperties "AllowBypassKey", dbBoolean, True
Beep
MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
"The Shift key will allow the users to bypass the startup & _
options the next time the database is opened.", _
vbInformation, "Set Startup Properties"
Else
Beep
SetProperties "AllowBypassKey", dbBoolean, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
"The Bypass Key was disabled." & vbCrLf & vbLf & _
"The Shift key will NOT allow the users to bypass the & _
startup options the next time the database is opened.", _
vbCritical, "Invalid Password"
Exit Sub
End If
Exit_bDisableBypassKey_Click:
Exit Sub
Err_bDisableBypassKey_Click:
MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
Resume Exit_bDisableBypassKey_Click
End Sub


However it keeps saying that the command: SetProperties is incorrect.

The first half of this is attached to the entire database to disable the
shift key. I THINK that bit is working. However the second half is not. Can
somebody either correct this script or send me a new one the WORKS please.

The other problem I am having is getting all of the records over 5 days old
to delete. Then adding dates for the following 2 weeks. (This database is for
booking out computers and I need users to be able to skip 2 weeks ahead to
book them but dont want to keep adding the dates manually.)

If you can solve both of these it would be greatly appreciated.

Tom
 
You are correct on the SetOption item.

However, now I have tried to run it, there are more problems further down
the script. Could you attempt to re-write the entire script for me, working

This would be a great help

Tom
 
You have too many things on your code, most of them are to check the 'special
options' and are readonly.

Anyway, I am just going to try to use you code and comment somethings out.
One word of warning, I don't have access in this machine so I can't test it.

Also, I can see some confusion in the setproperties function, which is
really not needed for this code. I would just get rid of it and replace the
SetProperties "AllowBypassKey", dbBoolean, False
and
SetProperties "AllowBypassKey", dbBoolean, True
by
Application.SetOption "AllowBypassKey", False
and
Application.SetOption "AllowBypassKey", True
respectively.

----amended code below----


Option Compare Database
Option Explicit

Public Function SetProperties(strPropName As String, _
varPropType As Variant, varPropValue As Variant) As Integer

On Error GoTo Err_SetProperties

Dim db As DAO.Database, prp As DAO.Property 'not needed

Set db = CurrentDb 'not needed
'db.Properties(strPropName) = varPropValue '????????

Application.SetOption "AllowBypassKey", varPropValue

SetProperties = True '
Set db = Nothing 'not needed



Exit_SetProperties:
Exit Function

Err_SetProperties:
If Err = 3270 Then 'Property not found ---- don't think this will
happen
Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
db.Properties.Append prp
Resume Next
Else
SetProperties = False
MsgBox "SetProperties", Err.Number, Err.Description
Resume Exit_SetProperties
End If
End Function
'***************** Code End ***************Once you have created the module,
then you will need to attach the following code to a command button (or
label, graphic etc.):

'***************** Code Start ***************
'Assign this to the OnClick event of a command button (or double-click event
'of a label or graphic) named "bDisableBypassKey"
'Change the "TypeYourBypassPasswordHere" default password to your password

Private Sub bDisableBypassKey_Click()
On Error GoTo Err_bDisableBypassKey_Click
'This ensures the user is the programmer needing to disable the Bypass Key
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
"Please key the programmer's password to enable the Bypass Key."
strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
If strInput = "TypeYourBypassPasswordHere" Then

'this line is not really needed. I would just type the command here but
'I will make the changes in the fuction
SetProperties "AllowBypassKey", dbBoolean, True

Beep
MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
"The Shift key will allow the users to bypass the startup & _
options the next time the database is opened.", _
vbInformation, "Set Startup Properties"
Else
Beep
SetProperties "AllowBypassKey", dbBoolean, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
"The Bypass Key was disabled." & vbCrLf & vbLf & _
"The Shift key will NOT allow the users to bypass the & _
startup options the next time the database is opened.", _
vbCritical, "Invalid Password"
Exit Sub
End If
Exit_bDisableBypassKey_Click:
Exit Sub
Err_bDisableBypassKey_Click:
MsgBox "bDisableBypassKey_Click", Err.Number, Err.Description
Resume Exit_bDisableBypassKey_Click
End Sub


Hope this helps
Rui
 
You are being a brilliant help.

This piece of code works but only on enabling the shift key there is not
function to disable it again. As the database is only set up to block the
shift key on start up, this code will just be put underneath the other one if
you get what I mean.

If you can find one piece of working code where I can have one single
passworded button on my opening form, that enables or disables the shift key
on start up, that would be great.

Alternatively, is there a way you can put a button on that just opens up the
back end automatically with-out any shift key's at all. If this is possible,
then it means I can just disable the shift key and that is it.

I know I am a pain, but you are being a great help. If you can let me know
of any further developments, or if you get a copy of Access and would like
the database I am working on to try your codes out on, then let me know.

Thanks for all of your efforts so far they are not going unnoted. If there
is anything that I can help you with just let me know. However, as you can
probably tell I'm not the best at these things. (Hopefully I will learn one
day)

Tom
 
I don't usually do this but since I started now I will finish it.

Below is a fully working module based on your code.
------------------------------
Public Function DisableBypassKey()
Dim strInput As String
Dim strMsg As String
Beep
strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
"Please key the programmer's password to enable the Bypass Key."
strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")

'switch security off
If strInput = "TypeYourBypassPasswordHere" Then
'extra
SetProperties "AllowBreakIntoCode", dbBoolean, True
'extra
SetProperties "AllowSpecialKeys", dbBoolean, True
SetProperties "AllowBypassKey", dbBoolean, True
Beep
MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
"The Shift key will allow the users to bypass the startup " & _
"options the next time the database is opened.", _
vbInformation, "Set Startup Properties"
Else 'switch security on
Beep
'extra
SetProperties "AllowBreakIntoCode", dbBoolean, False
'extra
SetProperties "AllowSpecialKeys", dbBoolean, False
SetProperties "AllowBypassKey", dbBoolean, False
MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
"The Bypass Key was disabled." & vbCrLf & vbLf & _
"The Shift key will NOT allow the users to bypass the " & _
"startup options the next time the database is opened.", _
vbCritical, "Invalid Password"
Exit Function
End If
End Function

Public Function SetProperties(strPropName As String, varPropType As Variant,
varPropValue As Variant) As Integer
On Error GoTo Err_SetProperties

Dim db As DAO.Database, prp As DAO.Property
Const conPropNotFoundError = 3270

Set db = CurrentDb
db.Properties(strPropName) = varPropValue
SetProperties = True
Set db = Nothing

Exit_SetProperties:
Exit Function

Err_SetProperties:
If Err = conPropNotFoundError Then 'Property not found
Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
db.Properties.Append prp
Resume Next
Else
SetProperties = False
MsgBox "SetProperties", Err.Number, Err.Description
Resume Exit_SetProperties
End If
End Function
------------------------------------

if this sorts your problem, please update this discussion to solved for
future reference.

Cheers
Rui
 
I know I am now being a pain but where do I place that new module based code
you gave me?

I cant attach it to a button because it is a function and not a SUB. There
must be an easy way to fix this. If you have Windows Live Messenger, add me
on there and I will try and give you remote access to my computer so you can
fix the problem.

As I said before I'm not very good at this and I really need this to be
sorted ASAP. Im not sure if giving me instructions on here is much good
anymore as I don't seem to be getting any closer. Please can you just help me
out and finish this bit of code for me. I have made the entire database and
all of its other bits of code, I even made this code work in an earlier
version but lost it in a fire.

Hope to speak soon and soon I am sure we can close this case as an answered
quesion

Tom

(e-mail address removed)
 
Why don't you just use Albert Kallal's utility to turn it on/off as needed. It tends to be a 'set it, distribute mdb into production, forget it' type of thing. The utility will set/reset as you need.

Look for By Pass ShiftKey Code at

http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html


--
Joan Wild
Microsoft Access MVP
:I know I am now being a pain but where do I place that new module based code
: you gave me?
:
: I cant attach it to a button because it is a function and not a SUB. There
: must be an easy way to fix this. If you have Windows Live Messenger, add me
: on there and I will try and give you remote access to my computer so you can
: fix the problem.
:
: As I said before I'm not very good at this and I really need this to be
: sorted ASAP. Im not sure if giving me instructions on here is much good
: anymore as I don't seem to be getting any closer. Please can you just help me
: out and finish this bit of code for me. I have made the entire database and
: all of its other bits of code, I even made this code work in an earlier
: version but lost it in a fire.
:
: Hope to speak soon and soon I am sure we can close this case as an answered
: quesion
:
: Tom
:
: (e-mail address removed)
:
: "Rui" wrote:
:
: > I don't usually do this but since I started now I will finish it.
: >
: > Below is a fully working module based on your code.
: > ------------------------------
: > Public Function DisableBypassKey()
: > Dim strInput As String
: > Dim strMsg As String
: > Beep
: > strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & _
: > "Please key the programmer's password to enable the Bypass Key."
: > strInput = InputBox(Prompt:=strMsg, title:="Disable Bypass Key Password")
: >
: > 'switch security off
: > If strInput = "TypeYourBypassPasswordHere" Then
: > 'extra
: > SetProperties "AllowBreakIntoCode", dbBoolean, True
: > 'extra
: > SetProperties "AllowSpecialKeys", dbBoolean, True
: > SetProperties "AllowBypassKey", dbBoolean, True
: > Beep
: > MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & _
: > "The Shift key will allow the users to bypass the startup " & _
: > "options the next time the database is opened.", _
: > vbInformation, "Set Startup Properties"
: > Else 'switch security on
: > Beep
: > 'extra
: > SetProperties "AllowBreakIntoCode", dbBoolean, False
: > 'extra
: > SetProperties "AllowSpecialKeys", dbBoolean, False
: > SetProperties "AllowBypassKey", dbBoolean, False
: > MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
: > "The Bypass Key was disabled." & vbCrLf & vbLf & _
: > "The Shift key will NOT allow the users to bypass the " & _
: > "startup options the next time the database is opened.", _
: > vbCritical, "Invalid Password"
: > Exit Function
: > End If
: > End Function
: >
: > Public Function SetProperties(strPropName As String, varPropType As Variant,
: > varPropValue As Variant) As Integer
: > On Error GoTo Err_SetProperties
: >
: > Dim db As DAO.Database, prp As DAO.Property
: > Const conPropNotFoundError = 3270
: >
: > Set db = CurrentDb
: > db.Properties(strPropName) = varPropValue
: > SetProperties = True
: > Set db = Nothing
: >
: > Exit_SetProperties:
: > Exit Function
: >
: > Err_SetProperties:
: > If Err = conPropNotFoundError Then 'Property not found
: > Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
: > db.Properties.Append prp
: > Resume Next
: > Else
: > SetProperties = False
: > MsgBox "SetProperties", Err.Number, Err.Description
: > Resume Exit_SetProperties
: > End If
: > End Function
: > ------------------------------------
: >
: > if this sorts your problem, please update this discussion to solved for
: > future reference.
: >
: > Cheers
: > Rui
: >
: > "Tom5" wrote:
: >
: > > You are being a brilliant help.
: > >
: > > This piece of code works but only on enabling the shift key there is not
: > > function to disable it again. As the database is only set up to block the
: > > shift key on start up, this code will just be put underneath the other one if
: > > you get what I mean.
: > >
: > > If you can find one piece of working code where I can have one single
: > > passworded button on my opening form, that enables or disables the shift key
: > > on start up, that would be great.
: > >
: > > Alternatively, is there a way you can put a button on that just opens up the
: > > back end automatically with-out any shift key's at all. If this is possible,
: > > then it means I can just disable the shift key and that is it.
: > >
: > > I know I am a pain, but you are being a great help. If you can let me know
: > > of any further developments, or if you get a copy of Access and would like
: > > the database I am working on to try your codes out on, then let me know.
: > >
: > > Thanks for all of your efforts so far they are not going unnoted. If there
: > > is anything that I can help you with just let me know. However, as you can
: > > probably tell I'm not the best at these things. (Hopefully I will learn one
: > > day)
: > >
: > > Tom
 
This problem has now been solved.

Special thanks to Rui, a brilliant help.

All the code that has been used is placed in all of the comments and you are
more than welcome to contact me for any support that you may need.

Thanks everyone

Tom
 
Back
Top