Results 1 to 1 of 1

Thread: [FAQ's: OD] How do I bypass my database's autoexec/startup macro?

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    [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:
    1. Public Sub SetBypassProperty()
    2.     Const DB_Boolean As Long = 1
    3.     ChangeProperty "AllowBypassKey", DB_Boolean, False
    4. End Sub
    5.  
    6. Public Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
    7.     Dim dbs As Object, prp As Variant
    8.     Const conPropNotFoundError = 3270
    9.  
    10.     Set dbs = CurrentDb
    11.     On Error GoTo Change_Err
    12.     dbs.Properties(strPropName) = varPropValue
    13.     ChangeProperty = True
    14.  
    15. Change_Exit:
    16.     Exit Function
    17.  
    18. Change_Err:
    19.     If Err = conPropNotFoundError Then    ' Property not found.
    20.         Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
    21.         dbs.Properties.Append prp
    22.         Resume Next
    23.     Else
    24.         ' Unknown error.
    25.         ChangeProperty = False
    26.         Resume Change_Exit
    27.     End If
    28. End Function
    Source: Access Help File
    Last edited by RobDog888; Jun 28th, 2006 at 03:19 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width