I want to search multiple fields of a subform from an unbound textbox on the main form, but it doesn't seem to be filtering anything. No error messages come up either. My code is:
Private Sub btnSearch2_Click()
Dim strfilter As String
If Me.GlobalSearch.Value <> "" Then
Me.FilterOn = False
Me.GlobalSearch.SetFocus
Else
strfilter = "(HarvestId LIKE '*" & Me.GlobalSearch.Value & "*' OR "
strfilter = strfilter & "AssignedTo LIKE '*" & Me.GlobalSearch.Value & "*' OR "
strfilter = strfilter & "HarvestStatus LIKE '*" & Me.GlobalSearch.Value & "*')"
End If
'If strfilter <> "" Then
'Me.Filter = strfilter
'Me.FilterOn = True
'Else
'Me.FilterOn = False
'End If
End Sub
Where GlobalSearch is the search textbox and HarvestId, AssignedTo and HarvestStatus the fields I want to search on in the subform. Why isn't the code working? Thanks Mari
Assuming your subform is called HarvestSub
, replace your commented code with something like:
If strfilter <> "" Then
Me.HarvestSub.Form.Filter = strfilter
Me.HarvestSub.Form.FilterOn = True
Else
Me.HarvestSub.Form.FilterOn = False
End If
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.