简体   繁体   English

在以编程方式更改的SQL后端Access数据库中查找筛选器下拉列表不完整

[英]Lookup Filter dropdown incomplete in programmatically altered SQL backend Access database

In this thread a user had problems with the lookup filter being missing in an acess database that had a SQL server backend. 在该线程中 ,用户遇到问题,即在具有SQL Server后端的访问数据库中缺少查找过滤器。 The problem was easily solved simply by checking on an option in the current database settings that allowed ODBC fields to also provide lookup filter dropdowns. 只需在当前数据库设置中检查一个选项即可轻松解决该问题,该选项允许ODBC字段也提供查找过滤器下拉菜单。

For those confused, the lookup filter is the excel like function in a datasheet view that allows you to click on the drop down of the field name and select individual values from that field for filters by a checkbox. 对于那些困惑的人,查找过滤器是数据表视图中的excel like函数,它允许您单击字段名称的下拉列表,并通过复选框从该字段中选择单个值以进行过滤。

I, however, have a slightly different problem. 但是,我有一个稍微不同的问题。 The checkbox to allow ODBC field filter lookups is active in the settings, so that's not an issue. 允许ODBC字段过滤器查找的复选框在设置中处于活动状态,因此这不是问题。 If I have a form that pulls data from a query, the lookup filters work fine, and are pre-populated with values in that field for filter selection. 如果我有一个从查询中提取数据的表单,则查找过滤器可以正常工作,并且在该字段中预先填充了用于过滤器选择的值。 If that record source is changed in VBA, however, say for example, a SQL statement that exactly matches that query, the lookup filter no longer works. 但是,如果该记录源在VBA中发生了更改(例如,一条与该查询完全匹配的SQL语句),则查找过滤器将不再起作用。 I tried creating a recordset and attaching it to the same form, creating a SQL statement and attaching it to the record source, and opening the form with arguments which are then used within the form's on load event to change the record source, all with the same result of no lookup filter. 我尝试创建一个记录集并将其附加到相同的表单,创建一个SQL语句并将其附加到记录源,然后使用参数打开表单,然后在表单的on load事件中使用这些参数来更改记录源,所有这些都与没有查找过滤器的结果相同。

Am I overlooking something? 我在俯视什么吗?

After HansUp replied, I floundered about trying to figure out what he meant and ran into it rather accidently. 在HansUp回答之后,我困惑于试图弄清楚他的意思,然后偶然地碰到了它。

Since the form is opened by another form where the SQL statement is pregenerated, I simply assigned the form's underlying query to a QueryDef object and applied the pregenerated SQL statement to the object's SQL property. 由于该表单是由另一个预先生成SQL语句的表单打开的,因此我仅将表单的基础查询分配给QueryDef对象,并将预生成的SQL语句应用于该对象的SQL属性。 When the form was subsequently opened, the new SQL statement was used and all the lookup filters worked properly. 随后打开表单时,使用了新的SQL语句,并且所有查找过滤器均正常工作。 I was quite pleased :D 我很高兴:D

Here's a quick run down of the code: 这是代码的简要介绍:

Dim db as Database
Dim qDef as QueryDef
Dim strSQL as String

'generate SQL statement and assign it to strSQL here'

Set qDef = db.QueryDefs("qryMyQuery")
qDef.SQL = strSQL
DoCmd.OpenForm "frmMyForm"  'frmMyForm is based of qryMyQuery'

Thanks, HansUp! 谢谢,HansUp!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM