过滤器使用文本框连续窗体窗体、过滤器、文本框

2023-09-08 11:09:42 作者:冷忆

我需要让用户使用过滤用户输入到一个文本框的值连续的形式。并且还嵌套的连续纸在导航子表单的一对夫妇的水平。这听起来很容易,但所有的例子,我觉得在网络上使用宏来代替VBA。

I need to let users filter a continuous form using values the user enters into a textbox. And the continuous form is also nested within a couple levels of navigation subforms. This sounds easy enough, but all the examples I find on the web use macros instead of vba.

我设置的结构,写了一个更新后的程序文本框txtFilter如下:

I set up the structure and wrote an AfterUpdate procedure for a textbox txtFilter as follows:

Private Sub txtFilter_AfterUpdate()
    Dim filterval As String
    filterval = txtFilter.Value
    With Forms!Main!NavigationSubform.Form!NavigationSubform.Form
        .Filter = "LastName Like " & filterval
        .FilterOn = True
    End With
End Sub

我已经打了不同的语法,但没有它似乎正常工作。下面是一个链接,从文件共享网站下载数据库的相关部分: http://jmp.sh/v / HGctZ4Ru74vDAjzN43Wq

谁能告诉我怎么改变这一点,以便用户可以使用文本框来筛选连续形成的?

Can anyone show me how to alter this so that users can use the textbox to filter the continuous form?

推荐答案

我把它用这个工作: .Filter =名字像&放大器; filterval和放大器;

需要那些烦人的字符串标识符甚至有时字符串。

Need those annoying String Identifiers even for strings sometimes.

好吧,为了让形式打开,没有记录,然后拉起只有你(或用户)指定是用最简单的一点返工的记录。 (我建议你使用的是拷贝,而不是原来的) 1:在您的连续形式,删除记录源;我们将使用后期绑定(金达) 2:然后删除下txtFilter框code,然后删除框本身。 3:添加一个组合框像这样的东西作为记录来源: SELECT DISTINCT myTable.LastName FROM mytable的ORDER BY myTable.LastName; (这将让你姓氏的唯一列表,以便知道如何拼写这个名字不会是必要的,再加上它保证至少有一个匹配) 4:在该组合框的更新事件后,加code是这样的:

Okay, To get the form to open with no records and then pull up just the records you (or the user) specifies is easiest with a bit of re-work. (I'd recommend you working with a copy and not your original) 1:On your Continuous Form, remove the Recordsource; we're going to use Late Binding (Kinda) 2:Then delete the code under the txtFilter box, then delete the box itself. 3:Add a comboBox with something like this as the recordsource: SELECT DISTINCT myTable.LastName FROM myTable ORDER BY myTable.LastName; (This will get you a unique list of last names so knowing how to spell the name will not be necessary, plus it assures at least one match) 4:In the After Update event of that combobox, add code like this:

Dim strSource As String
strSource = "SELECT mt.IntakeNumber, mt.ClientNumber, " & _
    "mt.LastName, mt.FirstName, mt.ConsultationDate " & _
    " FROM myTable mt " & _
    "WHERE (mt.LastName)= '" & Me.cboFilter.Value & "'"

Me.RecordSource = strSource
Me.Requery

很明显,我们需要改变的表和字段名称作为必要的,但希望你的想法。

Obviously you'll need to change the table and field names as necessary, but hopefully you get the idea.