ADODB RecordSet 作为 Access Report RecordSource
我在 Access 2003 中有一个简单的表单、一个查询和一个报表。我必须使用 VBA 在记录集中操作查询结果,然后将其作为报表的 RecordSource 传递到报表。
如果我将记录集声明为 RecordSet 并使用其 Name 属性作为报表的 RecordSource,那么它就可以工作。但是,因为我需要编辑记录集,所以我认为使用 ADODB RecordSet 会更容易,如下所示。
记录集在全局模块中声明为 Dim rs As ADODB.RecordSet
。 其余的代码是;
Dim db As Database
Set db = CurrentDb
Dim con As ADODB.Connection
Set con = CurrentProject.Connection
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = con
rs.Source = "Select * from XXX"
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
rs.Open
'manipulate rs here....'
我曾经将报告的 RecordSource 作为 myReport.RecordSource = rs.Name 传递。 但 ADODB 没有 Name 属性。
如何将此记录集作为其 RecordSource 传递到报表?
谢谢
I have a simple form, a query and a report in Access 2003. I have to manipulate the results from the query in a recordset using VBA and then pass it on to the report as its RecordSource.
If I declare the recordset as RecordSet and use its Name property as the RecordSource of the report then it is working. However, because I need to edit the recordset, I though it would be easier to use an ADODB RecordSet as below.
The records set is declared as Dim rs As ADODB.RecordSet
in a global module.
The rest of the code is;
Dim db As Database
Set db = CurrentDb
Dim con As ADODB.Connection
Set con = CurrentProject.Connection
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = con
rs.Source = "Select * from XXX"
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
rs.Open
'manipulate rs here....'
I used to pass the RecordSource of the report as myReport.RecordSource = rs.Name.
But the ADODB doesn't have a Name property.
How can I pass this recordset to the report as its RecordSource?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法将报表绑定到 mdb 中的 ADO 记录集,只能在 adp 中绑定:http://support。 microsoft.com/?id=287437
You cannot bind a report to an ADO recordset in an mdb, only in an adp: http://support.microsoft.com/?id=287437
我手头没有 Access 2003 的副本,但根据记忆,您只需
查看一下 Microsoft 知识库,看起来我的记忆仍然有效!
http://support.microsoft.com/kb/281998
I don’t have a copy of access 2003 to hand but from memory you just do
Just had a look on the Microsoft KB and it looks like my memory is still working!
http://support.microsoft.com/kb/281998