Sub SetBypassProperty()
Const DB_Boolean As Long = 1
ChangeProperty "AllowBypassKey", DB_Boolean, False
'--------------如果需要解开shift锁定可以用以下代码:
'ChangeProperty "AllowBypassKey", DB_Boolean, true
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
Public Function Changeproperty(Strpropname As String, Varproptype As Variant, _
Varpropvalue As Variant) As Integer
'功能: 试图对数据库属性进行设置,如果没有该属性,
' 则使用 Createproperty 方法将其添加到 Database 对象的 Properties 集合中。
' 因为这些属性只有至少设置过一次以后,才会显示在 Properties 集合中。
Dim prp As Property
Dim dbs As Database
Set dbs = CurrentDb
Const Conpropnotfounderror = 3270
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