解析访问代码 [英] Parsing Access Code
问题描述
我在访问中创建了一个搜索表单,其中包含用于搜索关键字的代码,然后创建包含结果的表:
I have a search form I creating in access with a code to search for keywords and then create a table with the results:
Like"*"&[FORMS]![Search_Form]![KW_Text]&"*"
基本上,它告诉它读取我输入的关键字并提取所有匹配的结果. 我希望能够在包含所有数据的表中键入多个单词,我对每个用逗号分隔的数据位都有多个关键字.因此,如果我键入Manager,它将返回所有带有Manager字样的结果,我希望能够键入Manager,Supervisor,并让它返回manager的所有结果和supervisor的所有结果.
WHich basically tells it to read the keyword i type in and pull up any matching results. I would like to be able to type in multiple words, in the table containing all the data I have multiple keywords for each bit of data all separated by comas. So if I type in Manager it returns all results with the word Manager in it, I would like to be able to type in Manager, Supervisor and have it return all results for manager and all results for supervisor.
推荐答案
我使用此代码.它会在您的字符串之间用空格分隔开或".我把这个处理过的字符串放在querydefs
I use this code. It create a OR between your sting separated by a space. I put this processed string in an querydefs
Function CreateOr(MyCriteria As String, MyField As String) As String
Dim MyChar As String
Dim MyUniqueCriteria As String
Dim MyFinalCriteria As String
Dim I, j As Integer
j = 0
For I = 1 To Len(MyCriteria)
MyChar = Mid(MyCriteria, I, 1)
If MyChar = " " Then
If j = 0 Then
MyFinalCriteria = MyFinalCriteria & MyField & "=" & MyUniqueCriteria
Else
MyFinalCriteria = MyFinalCriteria & " or " & MyField & "=" & MyUniqueCriteria
End If
MyUniqueCriteria = ""
j = j + 1
Else
MyUniqueCriteria = MyUniqueCriteria & MyChar
End If
Next
CreateOr = MyFinalCriteria
End Function
希望对您有帮助
这篇关于解析访问代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!