【问题标题】:Access 2016 Using combobox in SQL queryAccess 2016 在 SQL 查询中使用组合框
【发布时间】:2018-11-21 21:24:46
【问题描述】:

我正在尝试创建一个查询,该查询使用单个组合框的选择作为 WHERE 子句的一部分。

查询:

SELECT Database.Contact_ID, Database.[Full Name], Database.[Job Title], 
Institution.Institution, Database.Email, Database.[Email 2], Database.[Work 
phone], Database.[Work phone 2], Database.Mobile, Database.Notes, Database. 
[Date created], [Keyword Junction].Keywords, Database.[Record Type]

FROM Institution INNER JOIN (Keywords INNER JOIN ([Database] INNER JOIN 
[Keyword Junction] ON Database.[Contact_ID] = [Keyword Junction].Contact_ID) 
ON Keywords.Keyword_ID = [Keyword Junction].Keywords.Value) ON 
Institution.ID = Database.InstitutionLookup

WHERE ((Keywords.Keyword)=[Forms]![Keyword Search Mk 2]![SelectKeyword]);

“关键字搜索 Mk 2”表单是一个简单的弹出式表单,带有允许用户选择所需关键字的组合框。我可以在表单中选择关键字,但是当我运行搜索时,结果是空的。

之前的 WHERE 子句是:

WHERE ((Keywords.[Keyword]) Like "*" & [Forms]![Keyword Search Mk 2]! 
[SelectKeyword]  & "*");

这也有同样的问题。我也尝试过指定列号,例如

WHERE ((Keywords.[Keyword]) Like "*" & [Forms]![Keyword Search Mk 2]! 
[SelectKeyword].[Columns](1)  & "*");

再次没有运气。

感谢任何建议,谢谢。

【问题讨论】:

  • 你是如何运行查询的? (因为这会影响参数是否被评估为表单控件)。 Keyword 字段是组合框的绑定列吗?
  • @LeeMac 关键字字段未按照您的建议绑定,知道我缺少一个简单的解决方案。谢谢
  • 不客气,Tony,我已将解决方案添加为答案,以便将此问题标记为已解决以供其他人查看。
  • 感谢抱歉,我本来打算这样做,再次感谢您的帮助。

标签: vba ms-access-2016


【解决方案1】:

Per the conversation in the cmets, when a record is selected, the value of the ComboBox control will be equal to value of the field in the Row Source which corresponds to the Bound Column number.

例如,如果您的 Row Source 数据集包含三个字段,并且 Bound Column 设置为 2,则数据集中第二个字段的值将由表达式 [Forms]![YourFormName]![YourComboBox] 返回。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多