Disable the shift key upon startup of an Access database

Function ap_DisableShift()

'This function will disable the shift at startup causing

'the Autoexec macro and Startup properties to always be executed

On Error GoTo errDisableShift

Dim db As DAO.Database

Dim prop As Property

Const conPropNotFound = 3270

Set db = CurrentDb()

'This next line disables the shift key on startup.

db.Properties("AllowByPassKey") = False

'function successful

Exit Function

errDisableShift:

'The first part of this error routine creates the "AllowByPassKey

'property if it does not exist.

If Err = conPropNotFound Then

Set prop = db.CreateProperty("AllowByPassKey", _

dbBoolean, False)

db.Properties.Append prop

Resume Next

Else

MsgBox "Function 'ap_DisableShift' did not complete successfully."

Exit Function

End If

End Function

Function ap_EnableShift()

'This function will enable the shift key at startup causing

'the Autoexec macro and Startup properties to be bypassed

'if the user holds down the shift key when opening the database.

On Error GoTo errEnableShift

Dim db As Database

Dim prop As Property

Const conPropNotFound = 3270

Set db = CurrentDb()

'This next line disables the shift key on startup.

db.Properties("AllowByPassKey") = True

'function successful

Exit Function

errEnableShift:

'The first part of this error routine creates the "AllowByPassKey

'property if it does not exist.

If Err = conPropNotFound Then

Set prop = db.CreateProperty("AllowByPassKey", _

dbBoolean, True)

db.Properties.Append prop

Resume Next

Else

MsgBox "Function 'ap_DisableShift' did not complete successfully."

Exit Function

End If

End Function