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

    Question Unanswered: Cannot create the AllowByPassKey property

    Using Access 2002, and the code I gathered and just posted here.

    I receive an error when trying to create the property on a A2002 encrypted db. Moreover, the checks does not seem to work on my db:

    I first run
    AllowByPassKey False
    in the debug/immediate window, which seems to work.
    Then I close/reopen Access and the db, but none of the following functions will work:

    chkbypass, GetAllowBypassKey, ap_DisableShift

    Debugging the error, highlights a line like this:
    db.Properties("AllowByPassKey") = False
    - they all complain that the property does not exist...
    I have run compact and repair, both before and after trying to create and check for the existence of the property.

    Example:
    "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
    "

    See the samples in my previous posting, link:
    http://www.dbforums.com/showthread.p...79#post3692779

    D.
    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

    Question

    Hm. I do not receive a message when trying to create the property, have also tried in exclusive mode, and with two different databases, but Access does not create the property. I have tried to create a new function from the original code I found on the net, the main part of it looks like this:

    Code:
    Dim db As DAO.Database
        Dim prop As Property
        Set db = CurrentDb()
    
        'create the "AllowByPassKey property
        Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)
            db.Properties.Append prop
    I then get a Type Mismatch error, highlighting this line:
    Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)

    What am I doing wrong?

    D.
    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

    Lightbulb Fixed it by decompiling/recompiling, made a createfunction too

    OK, fixed it by decompiling, also made a separate function for creating the propety.

    Below is an explanation that I found among my notes/posting copies, do not know from which forum I got it in the first place. It is relevant if there is a problem creating the ByPassKey property, or compiling the db (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:

    "You can decompile any access database as follows :
    open access with the run command of your PC with the following line:
    msaccess /decompile
    Any database you open then in Access will be automatically decompiled. Compile it again and quit access
    Open Access the normal way
    Open the database again and the problem should be fixed."

    Now, run the function to create the AllowByPassKey property.

    Below is the last piece of code that I used to create this property on one of my dbs that had this problem. To run/create the property, type the function name in the debug/immediate window and press enter, after storing the function in a module in the current db.

    Code:
    Function CreateAbpKey()
    On Error GoTo err_CreateAbpKey
    
    '    Const conPropNotFoundError = 3270
        Dim db As DAO.Database
        Dim prop As Property
        Set db = CurrentDb()
    
        'create the "AllowByPassKey property
        Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)
            db.Properties.Append prop
    
    exit_CreateAbpKey:
        Exit Function
    
    err_CreateAbpKey:
        MsgBox Err.Description
        Resume exit_CreateAbpKey
    
    End Function
    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
    Cross-reference: For full descriptions, functions and example code on dealing with the AllowByPassKey property, see my original thread here:

    http://www.dbforums.com/showthread.p...11#post3693211

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

  5. #5
    Join Date
    Jun 2012
    Posts
    1

    My fix for the 'Type Mismatch' error.

    This is my first posting (trying to give something back).

    My bypass code was working, but then appeared to break in another database.

    I was also getting a Type Mismatch error on the line:
    Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False, True)

    The difference in the working database was in defining

    Dim prp As Property (BROKEN)

    to:

    Dim prp As DAO.Property (WORKS)


    I believe the following also works if needed:
    Dim db As DAO.Database
    Set db = CurrentDb()

    I cannot select the DAO 3.6 Objects Library reference, as I get a 'name conflicts with another...' type of error.

    Below is my working code. I also added DeleteBypassProperty() so I could delete the key and try recreating it. Since a key only needs to be created one time per new database, this allows more testing of the creating routine.

    The three Call test lines used in the Immediate Window are:

    call ShowBypassValueCreateIfNoPropertyExists()

    call DeleteBypassProperty()

    call ShowBypassValueCreateIfNoPropertyExists()


    - - - - -

    Public Sub ShowBypassValueCreateIfNoPropertyExists()
    '
    On Error GoTo Err_Handling ' Initialize error handling.
    '
    ' Subroutine ID used in error routine. Must manually update the string to reflect the subroutine name above.
    Dim CurrentSubroutineName As String
    CurrentSubroutineName = "Module Global_Subroutine_and_Function_Module - ShowBypassValueCreateIfNoPropertyExists"
    '''

    'Dim db As DAO.Database
    'Set db = CurrentDb()

    Dim prp As DAO.Property

    Dim dbug As Boolean

    ' Dbug = True to turn on popup messages.
    ' Dbug = False to disable popup messages.
    dbug = True
    'dbug = False

    ' This command will either print the current property to the Immediate Window,
    ' or force the error condition to occur.
    Debug.Print "-----> The database 'AllowBypassKey' property is set to: " & _
    CurrentDb.Properties("AllowByPassKey") & " <-----"


    Exit_Err_Handling: ' Label to resume after error.
    '
    ' Clear objects
    Set prp = Nothing
    'Set db = Nothing
    '
    Exit Sub ' Exit before error handler.
    '
    Err_SetAllowBypassTrue:
    Set prp = CurrentDb.CreateProperty("AllowByPassKey", dbBoolean, True)
    CurrentDb.Properties.Append prp
    If dbug = True Then Debug.Print " *** Creating the property: 'AllowByPassKey', and setting the value to True"
    Resume Next
    '
    Err_SetAllowBypassFalse:
    Set prp = CurrentDb.CreateProperty("AllowByPassKey", dbBoolean, False)
    CurrentDb.Properties.Append prp
    If dbug = True Then Debug.Print " *** Creating the property: 'AllowByPassKey', and setting the value to False"
    Resume Next
    '
    Err_Handling: ' Label to jump to 'On Error'.
    '
    ' If the Run-time error = 3270 (property not found), create the property and set to appropriate value.
    If Err = 3270 Then
    If dbug = True Then Debug.Print "'Error' Occured in: " & CurrentSubroutineName & _
    " Error Number: " & Err & " Error Description: " & Error$
    '
    ' SELECT ONLY ONE (ie: uncomment) of the following Goto Err_SetAllowBypass(True/False) Statements:
    '
    ' Use this Goto to create the AllowByPassKey and set it to True
    GoTo Err_SetAllowBypassTrue:
    '
    ' Use this Goto to create the AllowByPassKey and set it to false
    ''GoTo Err_SetAllowBypassFalse:
    '
    ' Safer (?) stop to catch further errors (unless gets stuck in an endless loop...)
    GoTo Err_Handling:
    End If
    '
    ' Some unspecified Run-time error has occured, handle with generic error code.
    '
    MsgBox " Error Occured in: " & CurrentSubroutineName & vbCrLf & vbCrLf & _
    " Error Number: " & Err & vbCrLf & vbCrLf & _
    "Error Description: " & Error$, vbOKOnly, "Error Message"
    '
    Resume Exit_Err_Handling
    '
    End Sub



    - - - - -



    Public Sub DeleteBypassProperty()
    '
    On Error GoTo Err_Handling ' Initialize error handling.
    '
    ' Subroutine ID used in error routine. Must manually update the string to reflect the subroutine name above
    Dim CurrentSubroutineName As String
    CurrentSubroutineName = "Module Global_Subroutine_and_Function_Module - ShowBypassValueCreateIfNoPropertyExists"
    '''

    CurrentDb.Properties.Delete "AllowBypassKey"


    Exit_Err_Handling: ' Label to resume after error.
    '
    Exit Sub ' Exit before error handler. (Subroutine Version)
    'Exit Function ' Exit before error handler. (Function Version)
    '
    Err_Handling: ' Label to jump to If gcfHandleErrors Then On Error.
    '
    ' Some unspecified Run-time error has occured, handle with generic error code.
    '
    MsgBox " Error Occured in: " & CurrentSubroutineName & vbCrLf & vbCrLf & _
    " Error Number: " & Err & vbCrLf & vbCrLf & _
    "Error Description: " & Error$, vbOKOnly, "Error Message"
    '
    Resume Exit_Err_Handling
    '
    End Sub

Posting Permissions

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