Hi all,
First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm very new to VBA,i tried to follow the instructions reported in the code,but i got no result,i still can use the shift key,can you explain in details how to use it correctly to enable/disable users from pressing shift key to view database windw?,the code i was talking about is the below
one:
'This code was originally written by Michael Kaplan.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Michael Kaplan
'
Function ChangePropertyD dl(stPropName As String, _
PropType As DAO.DataTypeEnu m, vPropVal As Variant) _
As Boolean
' Uses the DDL argument to create a property
' that only Admins can change.
'
' Current CreateProperty listing in Access help
' is flawed in that anyone who can open the db
' can reset properties, such as AllowBypassKey
'
On Error GoTo ChangePropertyD dl_Err
Dim db As DAO.Database
Dim prp As DAO.Property
Const conPropNotFound Error = 3270
Set db = CurrentDb
' Assuming the current property was created without
' using the DDL argument. Delete it so we can
' recreate it properly
db.Properties.D elete stPropName
Set prp = db.CreateProper ty(stPropName, _
PropType, vPropVal, True)
db.Properties.A ppend prp
' If we made it this far, it worked!
ChangePropertyD dl = True
ChangePropertyD dl_Exit:
Set prp = Nothing
Set db = Nothing
Exit Function
ChangePropertyD dl_Err:
If Err.Number = conPropNotFound Error Then
' We can ignore when the prop does not exist
Resume Next
End If
Resume ChangePropertyD dl_Exit
End Function
' *********** Code End ***********
Paste the above code into a module. Then you can use the following
procedures to disable and enable the shift key for when you need it.
Public Sub DisableShiftKey ()
If ChangePropertyD dl("AllowBypass Key", dbBoolean, False) Then
MsgBox "Shift key access disabled."
Else
Msgbox "An error occured."
End If
End Sub
Public Sub EnableShiftKey( )
If ChangePropertyD dl("AllowBypass Key", dbBoolean, True) Then
MsgBox "Shift key access enabled."
Else
Msgbox "An error occured."
End If
End Sub
One problem I note in my version of Access 2003. The error number for
property not in collection seems to be 3265 now, not 3270. If you get
the an error occured message, change the line:
Const conPropNotFound Error = 3270
to
Const conPropNotFound Error = 3265
This code will disable the shift key for everyone, including you. Make
sure that you put a button or give your self some way to run the enable
code even if you don't have access to the database window. Here's how
I do it.
On a form in the database, I almost always have some sort of
administration functions. I put two buttons on there, one for
disabling and one for enabling the shift key. If I am using user-level
security, I just restrict access to that form to only admins.
Otherwise, you can write a simple piece of code to force a password
prompt on the two buttons.
Private Sub cmdDisableShift _Click()
If MsgBox("Do you want to disable the shift key?", vbYesNo,
"Confirm") = vbYes Then
If InputBox("Passw ord:", "Restricted ") = "1234" Then
DisableShiftKey
Else
MsgBox "Incorrect password."
End If
Else
MsgBox "Shift key access is not disabled."
End If
End Sub
Private Sub cmdEnableShift_ Click()
If MsgBox("Do you want to enable the shift key?", vbYesNo,
"Confirm") = vbYes Then
If InputBox("Passw ord:", "Restricted ") = "1234" Then
EnableShiftKey
Else
MsgBox "Incorrect password."
End If
Else
MsgBox "Shift key access is not enabled."
End If
End Sub
Just replace 1234 with whatever password you want to use.
First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm very new to VBA,i tried to follow the instructions reported in the code,but i got no result,i still can use the shift key,can you explain in details how to use it correctly to enable/disable users from pressing shift key to view database windw?,the code i was talking about is the below
one:
'This code was originally written by Michael Kaplan.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Michael Kaplan
'
Function ChangePropertyD dl(stPropName As String, _
PropType As DAO.DataTypeEnu m, vPropVal As Variant) _
As Boolean
' Uses the DDL argument to create a property
' that only Admins can change.
'
' Current CreateProperty listing in Access help
' is flawed in that anyone who can open the db
' can reset properties, such as AllowBypassKey
'
On Error GoTo ChangePropertyD dl_Err
Dim db As DAO.Database
Dim prp As DAO.Property
Const conPropNotFound Error = 3270
Set db = CurrentDb
' Assuming the current property was created without
' using the DDL argument. Delete it so we can
' recreate it properly
db.Properties.D elete stPropName
Set prp = db.CreateProper ty(stPropName, _
PropType, vPropVal, True)
db.Properties.A ppend prp
' If we made it this far, it worked!
ChangePropertyD dl = True
ChangePropertyD dl_Exit:
Set prp = Nothing
Set db = Nothing
Exit Function
ChangePropertyD dl_Err:
If Err.Number = conPropNotFound Error Then
' We can ignore when the prop does not exist
Resume Next
End If
Resume ChangePropertyD dl_Exit
End Function
' *********** Code End ***********
Paste the above code into a module. Then you can use the following
procedures to disable and enable the shift key for when you need it.
Public Sub DisableShiftKey ()
If ChangePropertyD dl("AllowBypass Key", dbBoolean, False) Then
MsgBox "Shift key access disabled."
Else
Msgbox "An error occured."
End If
End Sub
Public Sub EnableShiftKey( )
If ChangePropertyD dl("AllowBypass Key", dbBoolean, True) Then
MsgBox "Shift key access enabled."
Else
Msgbox "An error occured."
End If
End Sub
One problem I note in my version of Access 2003. The error number for
property not in collection seems to be 3265 now, not 3270. If you get
the an error occured message, change the line:
Const conPropNotFound Error = 3270
to
Const conPropNotFound Error = 3265
This code will disable the shift key for everyone, including you. Make
sure that you put a button or give your self some way to run the enable
code even if you don't have access to the database window. Here's how
I do it.
On a form in the database, I almost always have some sort of
administration functions. I put two buttons on there, one for
disabling and one for enabling the shift key. If I am using user-level
security, I just restrict access to that form to only admins.
Otherwise, you can write a simple piece of code to force a password
prompt on the two buttons.
Private Sub cmdDisableShift _Click()
If MsgBox("Do you want to disable the shift key?", vbYesNo,
"Confirm") = vbYes Then
If InputBox("Passw ord:", "Restricted ") = "1234" Then
DisableShiftKey
Else
MsgBox "Incorrect password."
End If
Else
MsgBox "Shift key access is not disabled."
End If
End Sub
Private Sub cmdEnableShift_ Click()
If MsgBox("Do you want to enable the shift key?", vbYesNo,
"Confirm") = vbYes Then
If InputBox("Passw ord:", "Restricted ") = "1234" Then
EnableShiftKey
Else
MsgBox "Incorrect password."
End If
Else
MsgBox "Shift key access is not enabled."
End If
End Sub
Just replace 1234 with whatever password you want to use.
Comment