Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shift Key Module/Function

Status
Not open for further replies.

eggy168

Programmer
Mar 6, 2002
220
US
Hi,

I found the following codes online for disable/enable the Shift Key in Access. The Command Button works great with the right password. However, the module doesn't work which mean when I press and hold down Shift Key, I can still see the Start-Up options. Can anyone help me to solve this issue? Thank You.

Step 1:
I create a new Module (follow the online instruction), and the code is:

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

Step 2: I have a form with all common buttons for users, then I have a new button for me only,

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 = "TypeYourPasswordHere" 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 Password" & vbCrLf & vbLf & _
"The Key was disabled." & vbCrLf & vbLf & _
"The shift key will not allow the users to by pass the startup options the nex time the database is opened.", _
vbCritial, "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

 
your code looks correct. I am not sure if your expectations are correct. The startup options may need to get disabled by the "fullmenus". I use a similar function called "changeProperty" and use it something like this to lock it down further

Code:
Public Sub subSetUserProperties()
   ChangeProperty "AllowBypassKey", dbBoolean, False
   ChangeProperty "AllowFullMenus", dbBoolean, False
   ChangeProperty "AllowSpecialKeys", dbBoolean, False
   ChangeProperty "AllowBreakIntoCode", dbBoolean, False
   ChangeProperty "StartupShowDBWindow", dbBoolean, False
   ChangeProperty "", dbBoolean, False
End Sub

Also to verify your property is properly set correctly put a msgbox at the end of your procedure for test purposes.
MsgBox currentdb.Properties("AllowByPassKey").Value

See if it gets set to false. It does look correct.
 
Hi,

I added your code into the same module, but when I press and click the Shift key, I can still see the Start-up options. Users can still use the Shift key to see the design of queries, tables, and reports.

I wonder what did I do wrong?

Thank you.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top