在MS-ACCESS中创建交互式多字段搜索栏 [英] Creating an Interactive Multi Field Search Bar in MS-ACCESS
问题描述
我知道这可能是我想念的一件简单的事情,但我希望大家都能提供帮助.我正在尝试在表单中添加一个文本框,以允许用户输入搜索条件并使查询过滤记录以仅显示那些符合条件的记录.诀窍是我希望用户能够输入信息,并让它检查表单的所有字段并返回有效记录.
I know this is probably a simple thing I'm missing, but I'm hoping you all can help. I'm trying to add a textbox to my form that allows users to type in search criteria and have the query filter the records to only display those that qualify. The trick is I want the user to be able to type in info and have it check all the fields of the form and return records for any that are valid.
我使用要检查的字段设置了查询,并且观看了一些有关设置条件的教程,但是它们都可以与多个搜索栏一起使用.有没有办法只用1个呢?
I set up a query with the fields that I want checked and I watched a few tutorials on setting criteria, but they are all working with multiple search bars. Is there a way to do it with only 1?
Like "*" Or [Forms]![Publications Page]![FilterBox] OR "*"
这是我编写的条件表达式.它返回的记录不是我想要的记录,而且在我更改[FilterBox]中的内容后似乎也没有更改.我有4个字段在运行相同的条件.所有的想法和建议都将不胜感激!
This is the criteria expression I wrote. It returns records just not the ones I want and doesn't seem to change after I change what is in [FilterBox]. I have 4 fields I'm running this same criteria on. All thoughts and suggestions are greatly appreciated!
谢谢!
推荐答案
生成的条件应该类似于
[LastName] Like '*searchtext*' Or [FirstName] Like '*searchtext*' Or ...
因此,您必须设置一个这样的条件
So, you would have to set up a single criteria like this
Dim crit As String
crit = " Like '*" & Replace(Me!FilterBox, "'", "''") & "*' "
其中replace语句将单(')替换为2.这使用户可以在搜索框中输入撇号.
where the replace statement replces single (') by 2. This enables the user to enter an apostrophe in the search box.
现在您必须创建整个条件
Now you must create the whole criteria
crit = "[Field1]" & crit & "Or [Field2]" & crit & "Or [Field3]" & crit & "Or [Field4]" & crit
这篇关于在MS-ACCESS中创建交互式多字段搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!