Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Lightbulb Unanswered: ByPassKey - disabling, enabling, pw protecting - organised samples - part 1 of 2 :-)

    ByPassKey - disabling, enabling, pw protecting - organised samples
    - part 1 of 2 ...:

    (the below text can be found in the attached PDF as well)

    Hope this is useful and timesaving :-)
    kedaniel.

    References:
    http://oldlook.experts-exchange.com:...Q_20746964.htm
    l
    http://www.tek-tips.com/gfaqs.cfm/le...pid/181/fid/93
    http://www.mvps.org/access/general/gen0040.htm
    **************************

    Discussion extracts, ExpertsExchange.com:

    The AllowBypassKey is not a persistant property of the DB Project so you
    have to be careful looking for it's value, and expect as error if the DB
    designer has never set it before. You will get "Member or Data Object Not
    Found" if the property has not been appended to the Database Object
    Write your code with a special error trap to detect for this error (by
    number)
    The error condition equates to:
    currentdb.AllowBypassKey=True
    There are many properties of the DB object that must be used once before
    they are appended to the object, or you must code them into place.
    Application Window caption for another one.
    The Function GetAllowBypassKey() will return false if the AllowByPassKey
    property doesn't exist or it does exists and is set to false. Otherwise it
    will return true.

    http://www.experts-exchange.com/Data..._20602857.html -- the one directly below the accepted answer).
    What does this "?CurrentDb.AllowBypassKey" in the debug window report?

    Comment from The_JFG Date: 09/24/2003 11:46AM PDT
    "Member or Data Object Not Found"

    Comment from jadedata Date: 09/24/2003 11:54AM PDT
    This is why I was saying to write the code with that error trap in it
    specifically.

    Comment from joekendall Date: 09/24/2003 02:32PM PDT
    Combine what gwgaw has given you and this to do what you need.

    If GetAllowBypassKey = False Then
    AllowByPassKey True
    End If

    Public Sub AllowByPassKey(ByVal State As Boolean)
    Currentdb.createproperty("AllowByPassKey",dbboolea n,State)
    End Sub
    Joe

    Comment from The_JFG Date: 09/24/2003 03:25PM PDT
    What does this actually do?
    "Currentdb.createproperty("AllowByPassKey",dbboole an,True)"

    Comment from jadedata Date: 09/24/2003 03:55PM PDT
    It adds a Non-persistant property to the current project(db) object that
    can be recognized, set, changed.

    Comment from The_JFG Date: 09/24/2003 04:54PM PDT
    The property actually has three states
    True = True
    False = False
    Nonexistant = False

    The code needs to take that third possibility into account.

    ' ***************

    Module_Sec_functions

    ChkBypass

    'http://oldlook.experts-exchange.com:8080/Databases/MS_Access/Q_20746964.ht
    ml

    Public Function ChkBypass() As Boolean
    On Error GoTo ChkBypass_Err
    ChkBypass = CurrentDb.Properties("AllowBypassKey")
    ChkBypass_Exit:
    Exit Function
    ChkBypass_Err:
    Select Case Err
    Case 3270
    Resume ChkBypass_Exit
    Case Else
    MsgBox Error$ & vbTab & Err
    Resume ChkBypass_Exit
    Resume
    End Select
    End Function

    GetAllowBypassKey

    'Experts exchange:

    'The following function will return false if the 'AllowByPassKey property
    doesn't exist or it does exists
    ' and is set to false. Otherwise it will return true.
    Public Function GetAllowBypassKey() As Boolean
    On Error Resume Next
    GetAllowBypassKey = CurrentDb.Properties("AllowBypassKey")
    End Function

    ' ******************

    'Comment from The_JFG Date: 09/24/2003 04:54PM PDT

    '*----- In some Module -----*
    Function AllowByPassKey(ByVal State As Boolean)
    AllowByPassKey =
    Currentdb.createproperty("AllowByPassKey",dbboolea n,State)
    End Function
    '*--------------------------------*

    ap_Disable+Enable_Shift

    'http://www.tek-tips.com/gfaqs.cfm/lev2/4/lev3/27/pid/181/fid/93

    '---------------------------------------
    'SHIFT BYPASS: (AND ENABLE)
    '---------------------------------------

    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

    faq_DisableShiftKeyBypass

    Function faq_DisableShiftKeyBypass(strDBName as String, fAllow as
    Boolean) As Boolean
    On Error GoTo errDisableShift
    Dim ws As Workspace
    Dim db As DATABASE
    Dim prop As Property
    Const conPropNotFound = 3270
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(strDBName)
    db.Properties("AllowByPassKey") = Not fAllow
    faq_DisableShiftKeyBypass = fAllow
    exitDisableShift:
    Exit Function
    errDisableShift:
    'The AllowBypassKey property is a user-defined
    ' property of the database that must be created
    ' before it can be set. This error code will execute
    ' the first time this function is run in a database.
    If Err = conPropNotFound Then
    ' You must set the fourth DDL parameter to True
    ' to ensure that only administrators
    ' can modify it later. If it was created wrongly, then
    ' delete it and re-create it correctly.
    Set prop = db.CreateProperty("AllowByPassKey", _
    dbBoolean, False, True)
    db.Properties.Append prop
    Resume
    Else
    MsgBox "Function DisableShiftKeyBypass did not complete
    successfully."
    Faq_DisableShiftKeyBypass = False
    GoTo exitDisableShift
    End If
    End Function

    ' ********************

    This posting has 2 parts. This is part 1.
    (Next: SetProperties, ChangePropertyDDL, etc.)

    kedaniel.
    Attached Files Attached Files
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  2. #2
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Lightbulb ByPassKey - disabling, enabling, pw protecting - organised samples - part 2 of 2

    ByPassKey - disabling, enabling, pw protecting - organised samples

    - part 2 of 2 ...:

    The full text can be found in the PDF attached to part 1.

    kedaniel.

    ' ************************

    SetProperties

    '***************** Code Start ***************
    'Copy this function into a new public module.
    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

    '***************** Code End ***************

    ChangePropertyDdl

    http://www.mvps.org/access/general/gen0040.htm
    Securing AllowBypassKey
    Author(s)
    Michael Kaplan
    The Access help file documents the CreateProperty method as
    Set property = object.CreateProperty (name, type, value, DDL)
    where the last argument is documented as
    Part Description
    DDL Optional. A Variant (Boolean subtype) that indicates
    whether or not the Property is a DDL object. The default is False. If DDL
    is True, users can't change or delete this Property object unless they have
    dbSecWriteDef permission.
    The CreateProperty method is used to create or set the AllowBypassKey
    property to true, which prevents a user from bypassing the startup
    properties and the AutoExec macro. However, the sample code provided in
    the help files does not use the fourth DDL argument when making a call to
    CreateProperty. This means that anyone who can open the database can
    programmatically reset the AllowBypassKey value.
    Therefore, in order to restrict the change capabilities to only the Admins,
    set the fourth argument to True when calling CreateProperty. And don't lock
    yourself out!
    As a sample, here's how the CreateProperty method should be called in order
    to properly utilize the DDL argument. The current sample in Access Help
    Files is also listed below to help illustrate the differences.

    ' *********** Code Start ***********
    'This code was originally written by Michael Kaplan.
    'It is not to be altered or distributed,
    'except as part of an application.
    'You are free to use it in any application,
    'provided the copyright notice is left unchanged.
    '
    'Code Courtesy of
    'Michael Kaplan
    '

    Function ChangePropertyDdl(stPropName As String, _
    PropType As DAO.DataTypeEnum, vPropVal As Variant) _
    As Boolean
    ' Uses the DDL argument to create a property
    ' that only Admins can change.
    '
    ' Current CreateProperty listing in Access help
    ' is flawed in that anyone who can open the db
    ' can reset properties, such as AllowBypassKey
    '
    On Error GoTo ChangePropertyDdl_Err
    Dim db As DAO.Database
    Dim prp As DAO.Property
    Const conPropNotFoundError = 3270
    Set db = CurrentDb
    ' Assuming the current property was created without
    ' using the DDL argument. Delete it so we can
    ' recreate it properly
    db.Properties.Delete stPropName
    Set prp = db.CreateProperty(stPropName, _
    PropType, vPropVal, True)
    db.Properties.Append prp
    ' If we made it this far, it worked!
    ChangePropertyDdl = True
    ChangePropertyDdl_Exit:
    Set prp = Nothing
    Set db = Nothing
    Exit Function
    ChangePropertyDdl_Err:
    If Err.Number = conPropNotFoundError Then
    ' We can ignore when the prop does not exist
    Resume Next
    End If
    Resume ChangePropertyDdl_Exit
    End Function

    ' ********************

    Function ChangeProperty(strPropName As String, _
    varPropType As Variant, varPropValue As Variant) As Integer
    ' The current listing in Access help file which will
    ' let anyone who can open the db delete/reset any
    ' property created by using this function, since
    ' the call to CreateProperty doesn't use the DDL
    ' argument
    '
    Dim dbs As Database, prp As Property
    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
    ' *********** Code End ***********

    ImmediateDebugWindow

    "Type:
    ap_DisableShift and press <return>.
    You will not be able to use the shift key to get around the startup
    procedures (including the autoexec macro) until the ap_EnableShift is run
    on the application."

    '*********************

    *----- In some Form -----*
    Private Sub Button_Check_Click()
    If AllowByPassKey = True Then
    msgbox "The DB is not secured"
    Else
    msgbox "The DB is locked down"
    End If
    End Sub
    *----------------------------*

    '**********************

    MANUALLY:
    From ExpertsExchange discussion:

    "Try doing this in the debug window (ctrl-G to access it)
    ?CurrentDb.AllowBypassKey
    If you get an error the property has not been set yet.
    Then put
    Currentdb.createproperty("AllowByPassKey",dbboolea n,True)
    then try:
    ?CurrentDb.AllowBypassKey
    again
    "

    StartupFrm

    '***************** Code Start ***************
    'Assign this to the OnClick event of a command button (or double-click
    event
    'of a label or graphic) named "bDisableBypassKey"
    'Change the "TypeYourBypassPasswordHere" default password to your password

    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 = "TypeYourBypassPasswordHere" 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 ''AllowBypassKey'' Password!" & vbCrLf & vbLf & _
    "The Bypass Key was disabled." & vbCrLf & vbLf & _
    "The Shift key will NOT allow the users to bypass the startup options the
    next time the database is opened.", _
    vbCritical, "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
    '***************** Code End ***************

    This is part 2 of 2, as a reply to part 1.

    The full text can be found in the PDF attached to part 1.

    kedaniel.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  3. #3
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369
    Part 3:

    If you cannot successfully either compile the db or create the AllowByPassKey property:

    In my case just now, I could compile, but could not seem to create the property, so I de- and recompiled, which solved the problem.

    - see full description and I also posted an additional function there, "Function CreateAbpKey()":

    http://www.dbforums.com/showthread.p...07#post3693207

    D.
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

  4. #4
    Join Date
    Nov 2003
    Location
    Europe
    Posts
    369

    Lightbulb Check the References in VBE if you cannot create the property

    Tip:
    For a couple of the problematic dbs where I had problems with storing the property for the ByPassKey-prevention, I discovered that my settings/references to both ADO 2.7 and DAO 3.6 in my VB editor had suddenly been disabled/unchecked...

    As I did so many things back and forth, I am now not really sure what caused it, but think that when I got the type mismatch error pointing to the propertycreation line in the code, it could well be that in those situations the references was missing. For what reason I do not know, but when I both ensured those items were checked, saved, decompiled and recompiled the db, I then could create and set the AllowByPassKey property for those dbs as well...

    kedaniel
    Win-XP pro, Access 2002, ADO 2.7, DAO 3.6. English versions of apps/OS.

Posting Permissions

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