ADODB RecordSet 作为 Access Report RecordSource

发布于 2024-10-02 07:55:53 字数 731 浏览 10 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稍尽春風 2024-10-09 07:55:53

您无法将报表绑定到 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

陌伤ぢ 2024-10-09 07:55:53

我手头没有 Access 2003 的副本,但根据记忆,您只需

Set Me.Recordset = rs

查看一下 Microsoft 知识库,看起来我的记忆仍然有效!

http://support.microsoft.com/kb/281998

I don’t have a copy of access 2003 to hand but from memory you just do

Set Me.Recordset = rs

Just had a look on the Microsoft KB and it looks like my memory is still working!

http://support.microsoft.com/kb/281998

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文