Hi all, forgive me if I use any wrong terms as my VBA isn't very strong.
I have been tasked to create a multi-keyword search form, however, my form isn't working right and only the first record of the table is opened.
These are the codes that I am using for my search form. I have a feeling that I am not calling the variable from the after update portion the right way. Can anyone help me correct this?
I have been tasked to create a multi-keyword search form, however, my form isn't working right and only the first record of the table is opened.
Code:
Public Sub txtSearch_AfterUpdate()
Dim strWhere As String
Dim strWord As String
Dim varKeywords As Variant
Dim i As Integer
Dim IngLen As Long
'If Me.Dirty Then
'Me.Dirty = False
'End If
If IsNull(Me.txtSearch) Then
If Me.FilterOn Then
Me.FilterOn = False
End If
Else
varKeywords = Split(Me.txtSearch, " ")
If UBound(varKeywords) >= 99 Then
MsgBox "Too many words."
Else
For i = LBound(varKeywords) To UBound(varKeywords)
strWord = Trim$(varKeywords(i))
If strWord <> vbNullString Then
strWhere = strWhere & "Directory.FName Like ""*" & strWord & "*"" AND "
End If
Next
IngLen = Len(strWhere) - 4
If IngLen > 0 Then
Me.Filter = Left(strWhere, IngLen)
Me.FilterOn = True
Else
Me.FilterOn = False
End If
End If
End If
End Sub
Code:
Private Sub Command2_Click()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim filepath As String
Dim strSearch As String
Dim rst As DAO.Recordset
If IsNull(Me.txtSearch) Or Me.txtSearch = "" Then
MsgBox "Please type in your search keyword.", vbOKOnly, "Keyword Needed"
Me.txtSearch.BackColor = vbYellow
Me.txtSearch.SetFocus
Else
Set rst = CurrentDb.OpenRecordset("SELECT Directory.Directory FROM Directory WHERE (('" & strWhere & "'))")
If rst.EOF Then
MsgBox "File does not exist."
Else
Me.txtSearch.BackColor = vbWhite
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
filepath = rst![Directory]
Set wrdDoc = wrdApp.Documents.Open(filepath)
End If
End If
End Sub
These are the codes that I am using for my search form. I have a feeling that I am not calling the variable from the after update portion the right way. Can anyone help me correct this?