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.
Function ChangePropertyDdl(stPropName As String, _
PropType As DAO.DataTypeEnum, vPropVal As Variant) _
As Boolean
On Error GoTo ChangePropertyDdl_Err
Dim db As DAO.Database
Dim prp As DAO.Property
Const conPropNotFoundError = 3270
Set db = CurrentDb
db.Properties.Delete stPropName
Set prp = db.CreateProperty(stPropName, _
PropType, vPropVal, True)
db.Properties.Append prp
ChangePropertyDdl = True
ChangePropertyDdl_Exit:
Set prp = Nothing
Set db = Nothing
Exit Function
ChangePropertyDdl_Err:
If Err.Number = conPropNotFoundError Then
Resume Next
End If
Resume ChangePropertyDdl_Exit
End Function
Function ChangeProperty(strPropName As String, _
varPropType As Variant, varPropValue As Variant) As Integer
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
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
ChangeProperty = False
Resume Change_Bye
End If
End Function
|