通过SQL引用VBA记录集

时间:2021-01-22 15:40:16

I'd like to make a reference to a recordset via SQL FROM statement. Example.

我想通过SQL FROM语句引用一个记录集。例。

I have a Recordset called RS. What I want to do is the following, in VBA.

我有一个名为RS的Recordset。在VBA中,我想做的是以下内容。

SELECT * FROM RS

Is there a way?

有办法吗?

2 个解决方案

#1


2  

In general, no. They are two different languages and environments. In order to use information from one in the other, you either have to use VBA to send data to SQL to process or extract data from SQL to be used by VBA to process. If you wanted to process this using SQL, there are numerous solutions the simplest of which is to populate a table in the database with the contents of your recordset and then use that table in your query.

一般来说,没有。它们是两种不同的语言和环境。为了使用另一个中的信息,您必须使用VBA将数据发送到SQL以处理或从SQL中提取数据以供VBA处理。如果您想使用SQL处理此问题,则有许多解决方案,其中最简单的方法是使用记录集的内容填充数据库中的表,然后在查询中使用该表。

#2


0  

What kind of recordset do you have, DAO or ADO?

你有什么样的记录集,DAO或ADO?

If you have a populated ADO recordset and you need only a subset of it, you can use RS.Find to find single rows which match a certain criteria, or RS.Filter to filter out every row which doesn't match a certain criteria.
Be aware that this only works with ADO recordsets, not DAO recordsets!

如果您有一个填充的ADO记录集,并且只需要它的一个子集,则可以使用RS.Find查找符合特定条件的单个行,或使用RS.Filter过滤掉与某个条件不匹配的每一行。请注意,这仅适用于ADO记录集,而不适用于DAO记录集!

It' not exactly "Select * from RS", but maybe it helps you.

它不完全是“从RS中选择*”,但也许它可以帮到你。

#1


2  

In general, no. They are two different languages and environments. In order to use information from one in the other, you either have to use VBA to send data to SQL to process or extract data from SQL to be used by VBA to process. If you wanted to process this using SQL, there are numerous solutions the simplest of which is to populate a table in the database with the contents of your recordset and then use that table in your query.

一般来说,没有。它们是两种不同的语言和环境。为了使用另一个中的信息,您必须使用VBA将数据发送到SQL以处理或从SQL中提取数据以供VBA处理。如果您想使用SQL处理此问题,则有许多解决方案,其中最简单的方法是使用记录集的内容填充数据库中的表,然后在查询中使用该表。

#2


0  

What kind of recordset do you have, DAO or ADO?

你有什么样的记录集,DAO或ADO?

If you have a populated ADO recordset and you need only a subset of it, you can use RS.Find to find single rows which match a certain criteria, or RS.Filter to filter out every row which doesn't match a certain criteria.
Be aware that this only works with ADO recordsets, not DAO recordsets!

如果您有一个填充的ADO记录集,并且只需要它的一个子集,则可以使用RS.Find查找符合特定条件的单个行,或使用RS.Filter过滤掉与某个条件不匹配的每一行。请注意,这仅适用于ADO记录集,而不适用于DAO记录集!

It' not exactly "Select * from RS", but maybe it helps you.

它不完全是“从RS中选择*”,但也许它可以帮到你。