【问题标题】:where clause in a row source query for combo box组合框的行源查询中的 where 子句
【发布时间】:2014-12-12 19:12:31
【问题描述】:

我正在尝试创建一个组合框,其行源是查询。我想根据表单上控件之一中的某个值(可能会根据当前记录更改)或固定值(使用应用程序的用户名)过滤查询结果

假设我只想显示允许用户查看的项目

我想列出当前所选项目的任务。

我将 where 子句用作: where cmb_name.colname = me.control 这不起作用。

我尝试在组合框的行源中的查询中以及组合框调用的查询本身中插入此 where 子句 - 无论如何都不起作用。

最佳做法是什么?

【问题讨论】:

    标签: combobox ms-access-2010


    【解决方案1】:

    我会将其从查询移至 VBA 代码。使用 Form current 方法,您将能够做到这一点。

    Private Sub Form_Current()
        Me.comboBoxName.RowSource = "SELECT theFieldA, theFieldB FROM theTable " & _
                                    "WHERE theConditionFieldName = '" & Me.yourControlName & "'"
    
        'If the Me.yourcontrolName is a number value, please remove the single quotes in the above statement.
    
        Me.comboBoxName.ReQuery
    End Sub
    

    这样可以更好地控制选择。

    【讨论】:

      【解决方案2】:

      将表单的 Filter 属性设置为 colname = cmb_name,假设 cmb_name 是组合框,colname 是要过滤的列。 (过滤器不需要WHERE 关键字。)

      【讨论】:

        猜你喜欢
        • 2023-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多