会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > Access技巧 > DAO/ADO/ADP > 正文

使用 DAO 来设置和检索自定义数据库属性

时间:2009-06-12 08:45 来源:accessbbs 作者:Grant 阅读:
察看本文应用于的产品
注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成。微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章。然而由机器翻译的文章并不总是完美的。它可能存在词汇,语法或文法的问题,就像是一个外国人在说中文时总是可能犯这样的错误。虽然我们经常升级机器翻译软件以提高翻译质量,但是我们不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的错误使用所引起的任何直接的, 或间接的可能的问题负责。如果您发现了错误并希望帮助我们提高机器翻译技术,请完成文章末尾的在线调查。
文章编号 : 178745
最后修改 : 2007年1月22日
修订 : 4.3
本页
概要
更多信息
创建自定义属性和设置其值
检索自定义属性值
设置现有自定义属性的值
参考
概要
高级: 要求专家编码、 互操作, 和多用户技能。
当您单击文件菜单在 Microsoft access 7.0 或 97, 上数据库属性, 然后单击自定义选项卡, 可添加、 删除或修改数据库自定义属性。 本文介绍如何使用数据访问对象 (DAO) 来设置和检索自定义属性的数据库。

回到顶端
更多信息
Microsoft 提供编程示例仅, 供图示不附带任何明示或暗示。 这包括, 但不仅限于, 适销性或用于特定目的适用性的暗示保证。 本文假定您已熟悉与正在演示编程语言以及工具来调试过程来创建和使用。 Microsoft 支持工程师可以帮助解释功能的特定过程, 但它们将会修改这些示例以提供添加功能或构建过程以满足特定要求。 您可使用数据访问对象 (DAO) 来设置和检索自定义选项卡上单击文件菜单上数据库属性时显示自定义属性。 以访问这些属性编程, 您必须指向数据库容器对象中公开 < A0 > UserDefined < / A0 > 文档对象的 Properties 集合。
回到顶端
创建自定义属性和设置其值
要通过编程创建新自定义属性并设置其值, 请按照下列步骤: 1. 打开示例数据库 Northwind.mdb。  
2. 创建模块并声明部分中键入以下行如果它尚未有: Option Explicit
     

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
     

4. 要测试此过程, 在调试窗口, 键入以下行, 然后按 Enter。 要查看有效常量, 对于 prpType 参数, 搜索联机帮助了解 " 类型属性, " 可用显示 " Type 属性 (DAO) " 主题, 注意常量可用于属性对象。 CreateCustomProp "Language", dbText, "English"
     

5. 在文件菜单上, 单击数据库属性。  
6. 选择自定义选项卡。
注意属性列表中有 Language 属性值为 " 英语 "。  
回到顶端
检索自定义属性值
要检索值的自定义属性, 请按照下列步骤操作: 1. 打开示例数据库 Northwind.mdb。  
2. 在文件菜单上, 单击数据库属性。  
3. 选择自定义选项卡。  
4. 从名称列表, 选择编辑器。  
5. 值文本框中键入 " NancyDavolio " (不包括引号), 并单击添加。  
6. 单击确定以关闭属性对话框。  
7. 创建模块并声明部分中键入以下行如果它尚未有: Option Explicit
     

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
     

3. 要测试此过程, 在调试窗口, 键入以下行, 然后按 ENTER 键: SetCustomProp "Editor", "Andrew Fuller"
     

4. 在文件菜单上, 单击数据库属性。  
5. 选择自定义选项卡。
注意编辑器属性已更改从 " NancyDavolio " 到 " AndrewFuller "。

(责任编辑:admin)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: