Disable the SHIFT key bypass option (1 Viewer)

ajetrumpet

Banned
Local time
Yesterday, 22:16
Joined
Jun 22, 2007
Messages
5,638
By default, users can bypass any startup code or AutoExec macros that have been set to run in an Access database by simply holding down the SHIFT key while the file opens. To disable this bypass, you can use the following module:
Code:
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

Function BypassKey(onoff As Boolean)

   Const DB_Boolean As Long = 1
   ChangeProperty "AllowBypassKey", DB_Boolean, onoff
   
End Function
To disable:
Code:
BypassKey(False)
To enable:
Code:
BypassKey(True)
The change takes effect the next time the database is opened.
 

Users who are viewing this thread

Top Bottom