【译文】如何用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对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)
- 分享一下Access工程中的acw...(11.07)