vba ADODB 记录集作为访问报告记录源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4184871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 12:18:14  来源:igfitidea点击:

ADODB RecordSet as Access Report RecordSource

ms-accessvbaaccess-vbaadodbrecordset

提问by Sivakanesh

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.

我在 Access 2003 中有一个简单的表单、一个查询和一个报表。我必须使用 VBA 在记录集中处理查询结果,然后将其作为其 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.

如果我将记录集声明为 RecordSet 并使用其 Name 属性作为报告的 RecordSource,则它正在工作。但是,因为我需要编辑记录集,所以我认为使用 ADODB 记录集会更容易,如下所示。

The records set is declared as Dim rs As ADODB.RecordSetin a global module. The rest of the code is;

记录集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....'

I used to pass the RecordSource of the report as myReport.RecordSource = rs.Name. But the ADODB doesn't have a Name property.

我曾经将报告的 RecordSource 作为 myReport.RecordSource = rs.Name 传递。但是 ADODB 没有 Name 属性。

How can I pass this recordset to the report as its RecordSource?

如何将此记录集作为其记录源传递给报告?

Thanks

谢谢

采纳答案by Fionnuala

You cannot bind a report to an ADO recordset in an mdb, only in an adp: http://support.microsoft.com/?id=287437

您不能将报告绑定到 mdb 中的 ADO 记录集,只能在 adp 中:http: //support.microsoft.com/?id =287437

回答by Kevin Ross

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

我手头没有 access 2003 的副本,但从记忆中你就知道了

Set Me.Recordset = rs

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

刚刚查看了 Microsoft KB,看起来我的记忆还在工作!

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

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