【译文】如何用ADO代码实现窗体记录集的绑定
时 间:2013-12-24 08:59:20
作 者:周芳 ID:24526 城市:上海
摘 要:如何用ADO代码实现窗体记录集的绑定
正 文:
来自:微软 翻译:周芳
【译文】如何用ADO代码实现窗体记录集的绑定
将Microsoft Access 窗体绑定到一个记录集,你必须设置窗体的记录集属性为ADO记录集对象。这个窗体绑定到一个ADO记录集,更新时必须满足两个基本要求。基本要求是:
. 必须通过ADO更新
. 记录集必须包含一个或多个字段的惟一索引,比如一个表的主键。
VBA代码 :
Private Sub Form_Open(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'使用ADO连接
Set cn = CurrentProject.AccessConnection
'为ADO创建一个类实例
'设置它的属性
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn
.Source = "Select * FROM Customers"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
'用ADO给窗体的属性赋值
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
End Sub
【原文】How to: Bind a Form to an ADO Recordset
To bind a Microsoft Access form to a recordset, you must set the form's Recordset property to an open ADO Recordset object. A form must meet two general requirements for the form to be updatable when it is bound to an ADO recordset. The general requirements are:
•The underlying ADO recordset must be updatable via ADO.
•The recordset must contain one or more fields that are uniquely indexed, such as a table's primary key.
VBA:
Private Sub Form_Open(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
'Use the ADO connection that Access uses
Set cn = CurrentProject.AccessConnection
'Create an instance of the ADO Recordset class,
'and set its properties
Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn
.Source = "Select * FROM Customers"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.Open
End With
'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
End Sub
Access软件网官方交流QQ群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- 【Access选项卡示例】Ac...(09.09)
- 【Access源码示例】按输入...(09.02)
- 【Access日期区间段查询】...(08.29)
- 【Access日期区间段查询】...(08.27)
- Access怎样才能实现日期时...(08.21)
- 【Access定时打开查询】A...(08.19)
- Access生成固定数量的记录...(08.13)
- Access怎样才能实现日期时...(08.12)
- Access利用导航窗体控件对...(08.03)
学习心得
最新文章
- Access表中的字段名、字段标题...(09.19)
- Access快速开发平台--更改“...(09.18)
- 【中秋及国庆优惠】Access培训...(09.15)
- Access如何将日期型的数值转换...(09.14)
- 英文输入法输入数据中存在单引号引起...(09.11)
- 【Access选项卡示例】Acce...(09.09)
- 让Access光标停留在指定的控件...(09.07)
- 关于Access查询条件里使用通配...(09.06)
- Access报表偷懒制作法--Ac...(09.05)
- Access快速开发平台--窗体数...(09.04)