Hi,
I have a 1-table database and a split form accompanying it with a dynamic search box in its header. I really can't write VBA so I cribbed the dynamic search VBA from another post. It works fine until I add a new column into the table (TblAssets) for attachments. I can see why it would fail as it can't search the Attachments field, and so I'd like to edit this VBA so that it searches all fields except the field called Attachments.
For information, the error I get when typing into the search box is Runtime 3709, The search key was not found in any record.
Here's the code. I tried putting an If sField <> "Attachments" line in, but I clearly don't know what I'm doing. Any help gratefully received.
Code:
Private Sub txtFind_Change() Dim sFind, sField, sFilter As String
txtfind.SetFocus
sFind = Nz(txtfind.Text, "")
If Len(sFind) > 0 Then
Dim iField As Integer
sFilter = ""
For iField = 0 To iFields - 1
sField = rsMe.Fields(iField).Name
If iField > 0 Then sFilter = sFilter & " Or "
sFilter = sFilter & "[" & sField & "] Like '*" & sFind & "*'"
Next iField
Me.Filter = sFilter
Me.FilterOn = True
Else
Me.Filter = ""
Me.FilterOn = False
End If
txtfind.SetFocus
If bFindLastKeySpace Then
txtfind.Value = txtfind.Value & " "
txtfind.SelStart = Len(sFind) + 2
Else
txtfind.SelStart = Len(sFind) + 1
End If
txtfind.SelLength = 0
bFindLastKeySpace = False
End Sub