MS Access,通过复杂标准的查询。标准包括选择参数和vba函数

时间:2021-01-03 04:34:45

I currently have multiple queries that query data from a few tables linked through ODBC, and some temporary tables that are edited through the user interface. I have complex criteria in my queries such as:
SELECT * from ThingsData
WHERE (Thing In(SELECT Thing from ListOfThings) AND getThingFlag() = True);
In this case Thing is a field and ListOfThings is a temporary table that the user defines from the user interface. Basically, the user puts together a list of the field Thing that he/she wants to filter the data based on and I want to query only the data that matches the Thing values that the user adds to his/her list. Currently, the data I am querying is in the linked ODBC table, and the temp table ListOfThings is just a regular, local table and everything works peachy. I want to get rid of the linked table and use a pass through query instead. However, when i do that, unless the criteria is incredibly simplistic, i get an error:

我目前有多个查询来查询通过ODBC链接的几个表中的数据,以及一些通过用户界面编辑的临时表。我的查询中有一些复杂的条件,例如:来自ThingsData WHERE的SELECT *(Thing In(SELECTTing from ListOfThings)AND getThingFlag()= True);在这种情况下,Thing是一个字段,ListOfThings是用户从用户界面定义的临时表。基本上,用户将他/她想要过滤数据的字段列表放在一起,并且我想仅查询与用户添加到他/她的列表中的Thing值匹配的数据。目前,我查询的数据是在链接的ODBC表中,临时表ListOfThings只是一个常规的本地表,一切都很好用。我想摆脱链接表并使用传递查询代替。但是,当我这样做时,除非标准非常简单,否则我会收到错误:

"ODBC--Call Failed. Invalid object name ListOfThings."

“ODBC - 调用失败。无效的对象名称ListOfThings。”

If I dont have any criteria it works fine.

如果我没有任何标准,它可以正常工作。

Long story short: In a pass through query, how do I apply criterias that include SELECTs and functions from my modules and just basically filter the pass through table based on data from my local tables?

简而言之:在传递查询中,如何应用包含我的模块中的SELECT和函数的标准,并基本上根据本地表中的数据过滤传递表?

1 个解决方案

#1


0  

What is at the other end of that ODBC link? In a pass-through query you will have to honor the syntax required by the database server, not Access syntax. I would first suspect that you can't have mixed case table names and I would try listofthings as the name.

ODBC链接的另一端是什么?在传递查询中,您必须遵守数据库服务器所需的语法,而不是Access语法。我首先怀疑你不能有混合的案例表名称,我会尝试listofthings作为名称。

If you have a tool that can be used to test queries directly against the database server, get the query working there and then simply cut and paste it into an Access pass-through query.

如果您有一个可用于直接针对数据库服务器测试查询的工具,请在此处进行查询,然后将其剪切并粘贴到Access传递查询中。

#1


0  

What is at the other end of that ODBC link? In a pass-through query you will have to honor the syntax required by the database server, not Access syntax. I would first suspect that you can't have mixed case table names and I would try listofthings as the name.

ODBC链接的另一端是什么?在传递查询中,您必须遵守数据库服务器所需的语法,而不是Access语法。我首先怀疑你不能有混合的案例表名称,我会尝试listofthings作为名称。

If you have a tool that can be used to test queries directly against the database server, get the query working there and then simply cut and paste it into an Access pass-through query.

如果您有一个可用于直接针对数据库服务器测试查询的工具,请在此处进行查询,然后将其剪切并粘贴到Access传递查询中。