3. 键入以下过程: 'The following procedure accepts three arguments: prpName, prpType, 'and prpValue. ' 'prpName: a String value representing the name of the property ' you want to create. ' 'prpType: an Integer value representing the data type of the ' property you want to create. To view valid settings for ' this argument, search online help for "Type property," ' display the topic "Type property (DAO)" and note the ' constants available for Property objects. ' 'prpValue: a Variant value representing the value of the property ' you want to create. ' Sub CreateCustomProp(prpName As String, prpType As Integer, _ prpValue As Variant) Dim db As Database Dim doc As Document Dim prp As Property Set db = CurrentDb Set doc = db.Containers!Databases.Documents!UserDefined Set prp = doc.CreateProperty() With prp .Name = prpName .Type = prpType .Value = prpValue End With doc.Properties.Append prp End Sub
8. 键入以下过程: 'The following procedure accepts one argument: prpName ' 'prpName: a String value representing the name of the property ' whose value you want to retrieve. ' Function GetCustomProp(prpName As String) As Variant Dim db As Database, prp As Property Dim doc As Document Set db = CurrentDb Set doc = db.Containers!Databases.Documents!UserDefined On Error Resume Next Set prp = doc.Properties(prpName) If Err.Number = 0 Then GetCustomProp = prp.Value Else MsgBox "Property Not Found" GetCustomProp = Null End If End Function
9. 要测试此函数, 在调试窗口, 键入以下行, 然后按 ENTER 键: ?GetCustomProp("Editor")
注意 " NancyDavolio " 返回到调试窗口。 回到顶端 设置现有自定义属性的值 要设置值现有自定义属性, 请按照下列步骤: 1. 按照 1 - 7 " 检索值为自定义属性 " 部分中。 2. 键入以下过程: 'The following procedure accepts three arguments: prpName, and 'prpValue. ' 'prpName: a String value representing the name of the property ' you want to create. ' 'prpValue: a Variant value representing the value of the property ' you want to set. '
Sub SetCustomProp(prpName As String, prpValue) Dim db As Database, doc As Document Dim prp As Property Set db = CurrentDb Set doc = db.Containers!Databases.Documents!UserDefined Set prp = doc.Properties(prpName) prp.Value = prpValue End Sub