A
Ac
I try to write a program for a user to search a word that is a partial word
inside of the record. I created a table containing the fields Files and
Descriptions, and a form named fSearch; there are two text boxes txtFiles and
txtDescriptions to take the inputs from user and a cmdSearch button; if the
user typed the word in the txtFiles or txtDescriptions, is a part of the word
inside of the Files or the Descriptions in the table, then the corresponding
record will be retrieved and displayed on the form named fMain.
I try to use the function InStr behind the cmdSearch button, but the result
did not come right. If it does not asked too much, could you help me for the
code? Or
should I use different function? Please give me an advice, thanks.
Here is the code:
Private Sub cmdSearch_Click()
Dim strWhere As String
Dim Result As Integer
strWhere = ""
If Not IsNull(Me.txtTitle) Then
Result = InStr(1, Files.[Title], Me.txtTitle)
If Result > 0 Then
strWhere = "[Title]=""" & Files.[Title] & """"
End If
End If
If Not IsNull(Me.txtDescription) Then
If (InStr(1, Files.[Description], Me.txtDescription)) > 0 then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "[Description] =""" & Files.[Description] & """"
End If
Private Function AddAnd(strFilterString) As String
If Len(strFilterString) > 0 Then
AddAnd = strFilterString & "AND"
Else
AddAnd = strFilterString
End If
End Function
inside of the record. I created a table containing the fields Files and
Descriptions, and a form named fSearch; there are two text boxes txtFiles and
txtDescriptions to take the inputs from user and a cmdSearch button; if the
user typed the word in the txtFiles or txtDescriptions, is a part of the word
inside of the Files or the Descriptions in the table, then the corresponding
record will be retrieved and displayed on the form named fMain.
I try to use the function InStr behind the cmdSearch button, but the result
did not come right. If it does not asked too much, could you help me for the
code? Or
should I use different function? Please give me an advice, thanks.
Here is the code:
Private Sub cmdSearch_Click()
Dim strWhere As String
Dim Result As Integer
strWhere = ""
If Not IsNull(Me.txtTitle) Then
Result = InStr(1, Files.[Title], Me.txtTitle)
If Result > 0 Then
strWhere = "[Title]=""" & Files.[Title] & """"
End If
End If
If Not IsNull(Me.txtDescription) Then
If (InStr(1, Files.[Description], Me.txtDescription)) > 0 then
strWhere = AddAnd(strWhere)
strWhere = strWhere & "[Description] =""" & Files.[Description] & """"
End If
Private Function AddAnd(strFilterString) As String
If Len(strFilterString) > 0 Then
AddAnd = strFilterString & "AND"
Else
AddAnd = strFilterString
End If
End Function