Settings only administrators can change the AllowBypassKey property

Source: Internet
Author: User
Tags exit goto reset
Tmtony translation:

The syntax for the CreateProperty method is described in the Help file for access:

The Set property = object. CreateProperty (name, type, value, DDL)
In fact, the last parameter is this explanation (partially described):

DDL Optional. A variable (logical subtype) Specifies whether this property is a DDL object. The missing value is false. If set to True, the user cannot change or delete this property unless he has dbsecwritedef permissions
CreateProperty is used to create or set the AllowBypassKey property if this property is set to True, you can disable the user's near Shift key to prevent startup properties and AutoExec macros. However, the examples provided in Access Help do not use the fourth DDL Parameters. This means that anyone can open the data and then use the program to reset the AllowBypassKey attribute.

So, to limit the average user to changing this property, we set the fourth argument to true.

For comparison, we also list examples of Access itself to refer to

' *********** Code Start ***********
Function Changepropertyddl (Stpropname as String, _
Proptype as DAO. DataTypeEnum, Vpropval as Variant) _
As Boolean
' Uses the DDL argument to create a property
' That's only Admins can change.
'
' Current CreateProperty listing into Access help
' is flawed in ', 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 is 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 prop does not exist
Resume Next
End If
Resume Changepropertyddl_exit
End Function

Examples of help itself
Function ChangeProperty (strPropName as String, _
Varproptype As Variant, Varpropvalue as Variant) as Integer
' The current listing in Access Help file which would
' Let anyone who can open the DB delete/reset any
' Property created by using this function, since
' The call to Craeteproperty 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 ' 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 ***********


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.