Results 1 to 5 of 5
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    user defined property

    Hi

    my reading has shown me that you can add a macro to the autoexec to prevent the enduser being able to use the shift key to bypass the start up files. (https://support.office.com/en-us/art...5-b0f1deac517b)

    The code is given:

    Code:
    Sub SetBypassProperty()
    Const DB_Boolean As Long = 1
        ChangeProperty "AllowBypassKey", DB_Boolean, False
    End Sub
    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_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
    And I have to use it my creating a user defined property.

    BUt I seem unable to discover how to create a user defined property.

    Any advice and links as usual gratefully received]

    thanks

    Ian

  2. #2
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Went to the link - don't understand your remark re user defined property. You're trying to set a database property if it's in the collection, or add it then set it if it's not. I wouldn't call that user defined, but then, I don't claim to know everything. You can lock yourself out of a db with this property, so I'd provide a means of cycling it to prevent that. Here's what I do. Some form label (I use an About form) has a double click event known to the power users or developers of the db. I think this routine is a bit more powerful and maybe even simpler to follow than what you posted:
    Code:
    Sub setDisableMode() 'called by dbl click event on the 'about' form
    Dim mode As Boolean
    Dim db As DAO.Database
    Dim prop As DAO.Property
    
    On Error GoTo errHandler
    Set db = CurrentDb
    Set prop = db.Properties("AllowByPassKey") 'if prop does not exist, error 3270 is raised.
    
    If dbUser.Level = "admin" Then 'dbUser is a user defined object, not property or function
        If prop = True Then 'bypass enabled; change it to false
            mode = False 'switch the mode to False
            prop = apDisableShift(mode) 'pass the mode to the function
            DoCmd.SelectObject acForm, "frmAbout", False 'select frmAbout, which is still open
            Forms!frmAbout.lblVersion.BackColor = 16777215 set the label background to white
        Else: 'assume prop is false
            mode = True 'pass this mode to the function
            prop = apDisableShift(mode) 'pass mode to the function
            DoCmd.SelectObject acForm, "frmAbout", False
            Forms!frmAbout.lblVersion.BackColor = 255 'set label background to red as visual clue
        End If
    MsgBox "Enable bypass is now " & prop 'let user know the new value was set
    
    Set db = Nothing
    Set prop = Nothing
    Exit Sub
    End If
    
    MsgBox "You must be an administrator to change settings."
    
    exitHere:
    Set db = Nothing
    Set prop = Nothing
    Exit Sub
    
    errHandler:
    If Err.Number = 3270 Then 'bypass property doesn't exist so create it
        Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False)
        db.Properties.Append prop
        Resume
    End If
    MsgBox Err.Number & ": " & Err.Description
    Resume exitHere
    End Sub
    This piece takes the argument from the sub and cycles the property
    Code:
    Function apDisableShift(mode) As Boolean
    CurrentDb.Properties("AllowByPassKey") = mode
    apDisableShift = mode
    End Function
    Last edited by Micron; 04-23-2016 at 01:19 PM. Reason: fixed code comments
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    userdefind property

    THanks for the input off to inspect and try to understand your code.

    As to where I got the User defined property bit, on the page link I sent you it says

    "In a Microsoft Access database (.mdb or .accdb), you can add the property by using the CreateProperty method and then appending it to the Properties collection of the Database object."

    But clearly I've confused myself.

    I do take you point relocking myself out of the database so perhaps I'll give it more thought.

    I suppose that in reality as the database is for use by enthusiastic volunteers in a helpgroup/charity they are unlikely to search for a way into the tables. Perhaps it was just me being too enthusiastic

    cheers

    Ian

  4. #4
    Micron is online now Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    There's an old saying about being too late to close the barn door after the horses have escaped. You have to weigh the probability of anyone messing around against the work it involves. However, some basic protection is not a bad thing and is best done before you wish you had. If nothing else, it might be a useful learning exercise for you.

    For basic protection, I recommend splitting the db, setting the AllowBypass property to no (but make it easy to cycle for those who know), password protecting the back end, and linking the back end tables with that password employed. Is that very, very secure? No, I can over-ride your bypass property from another database and locate the password, but chances are no one in your group can do that (maybe not even you at this point), so it likely provides all the protection you're likely to need for now if not ever.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    HI

    point taken thanks for the input

    Ian

Please reply to this thread with any new information or opinions.

Similar Threads

  1. mydb - User-defined type not defined
    By adams77 in forum Forms
    Replies: 4
    Last Post: 07-22-2015, 08:43 AM
  2. Replies: 3
    Last Post: 11-12-2013, 04:13 PM
  3. user-defined type not defined
    By markjkubicki in forum Programming
    Replies: 3
    Last Post: 05-09-2013, 05:15 PM
  4. Replies: 1
    Last Post: 12-14-2012, 12:32 AM
  5. Replies: 4
    Last Post: 06-08-2012, 09:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums