ms-accessfilteringsubformdatasheet

MS ACCESS - How to filter a subform datasheet by a main form's textbox like a searchbox


I have a main form1 (formview) and a subform2 (datasheetview) based on the same query like a splitform.

In the main form1 i have a textbox that i want to use like a searchbox for the subform2.

This searchbox has to filter the subform2 datasheet by searching in 3 different fields (name, type, number) and when finding a record that matches the searchbox's value, it has to filter the datasheet by this value.

I tried with macro Applyfilter and VBA but didn't succed.. Can someone help me?


Solution

  • Consider:

    Private Sub tbxSearch_AfterUpdate()
    Me.ctrDS.Form.Filter = "Member_name LIKE '*" & Me.tbxSearch & "*' OR TypeOfBusiness LIKE '*" & Me.tbxSearch & "*' OR Member_ContactNumber='" & Me.tbxSearch & "'"
    Me.FilterOn = True
    End Sub
    

    Or

    Private Sub tbxSearch_AfterUpdate()
    With Me.ctrDS.Form.RecordsetClone
        .FindFirst "Member_name LIKE '*" & Me.tbxSearch & "*' OR TypeOfBusiness LIKE '*" & Me.tbxSearch & "*' OR Member_ContactNumber='" & Me.tbxSearch & "'"
        If Not .NoMatch Then Me.ctrDS.Form.Bookmark = .Bookmark
    End With
    End Sub