【问题标题】:Access 2016 - Multiple text fields - Search as you type not workingAccess 2016 - 多个文本字段 - 键入时搜索不起作用
【发布时间】:2017-07-07 12:22:34
【问题描述】:

我有一个 Access 2016 表单,其中包含 5 个标记为 txtprod、txtpri、txtcnt、txtph、txtmfg 的文本框。我还对我的表进行了产品名称、价格、计数、电话和制造商字段的查询。

在我的表单 5 文本框中,我希望能够在您键入时自动搜索并自动填充我的列表。

我遵循了这些教程 https://www.youtube.com/watch?v=SJLQqwMOF08 https://www.youtube.com/watch?v=MwaRFjgwBW8

我的表单有表单加载:

*私有子表单_Load() 将任务变暗为字符串 任务=“选择*从定价数据” Me!details.RowSource = 任务 结束子*

我的文本框名称有这个事件“on change”

*私有子 txtprod_Change() 将任务变暗为字符串 task = "SELECT * FROM [pricingdata] WHERE ([Product Name] LIKE '" & Me.txtprod.Text & "');" Me!details.RowSource = 任务 结束子*

在我输入时进行搜索,只需 1 个文本框即可完美运行。但是,当我将以下代码添加到“更改时”的制造商文本框事件中时,它无法按预期工作。

*私有子 txtmfg_Change() 将任务变暗为字符串 task = "SELECT * FROM [pricingdata] WHERE ([Manufacturer] LIKE '" & Me.txtmfg.Text & "');" Me!details.RowSource = 任务 结束子*

现在当我输入我的产品名称文本框时,它搜索产品就好了。当我开始在制造商文本框中输入内容时,它会完全忽略我在产品名称文本框中输入的任何内容并开始搜索,因为我只在制造商文本框字段中输入文本。

如何进行此设置,以便所有 5 个文本框字段中的所有文本都有助于将搜索过滤器应用于我的列表?

【问题讨论】:

    标签: vb.net ms-access


    【解决方案1】:

    类似这样的东西。 . .

    Private Sub ComboSelect_Change()
    
        '  You need to use String delimiters if you want to use a Text Field like:
        '  Me.Filter "[ATextFieldInRecordSource] = """ & Me.FilterComboBox & """"
    
        '  For a Numeric Field, use something like this:
        '  Me.Filter "[ANumericFieldInRecordSource] = " & Me.FilterComboBox
        '  Me.FilterOn = True
    
        Me.[Customer_Query subform1].Form.Filter = "[Company_Name] Like '*" &
                         Replace(Me.ComboSelect.Text, "'", "''") & "*'"
        Me.[Customer_Query subform1].Form.FilterOn = True
    
    End Sub
    
    Notice a few things:
    
        The subform is named Customer_Query subform1’
        The combobox is named ComboSelect’
        Finally, the ‘like clause’ is used in combination with the wildcard character.
        Like '*" & Replace(Me.ComboSelect.Text, "'", "''") & "*'"
    

    当您在组合框中键入文本时,会动态重新查询子表单中的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      • 2011-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      相关资源
      最近更新 更多