[FAQ's: OD] How do I bypass my database's autoexec/startup macro?
One of the easiest ways to execute macro code at the startup of an Access database is to use Access' autoexec macro. You can apply security, GUI changes like hiding certain toolbars and menus, showing a startup form, etc. Although, this is also the easiest method to circumvent by pressing down and holding the shift key before you double left click the database in windows explorer. The AllowBypassKey property bypass' the startup properties and the AutoExec macro.
You can turn on and off the Shift Key (AllowBypassKey) behavior during startup by writting VBA code:
AllowBypassKey:
Determines if the SHIFT key can be used to bypass the application load processes such as the running of the autoexec macro or the startup properties. The property's setting doesn't take effect until the next time the database opens. You should make sure the AllowBypassKey property is set to True when debugging an application.
True: Enable the SHIFT key to allow the user to bypass the startup properties and the AutoExec macro.
False: Disable the SHIFT key to prevent the user from bypassing the startup properties and the AutoExec macro.
Access 2003 VBA Code Example:
VB Code:
Public Sub SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
End Sub
Public 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_Exit:
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_Exit
End If
End Function
Source: Access Help File