Click here to Skip to main content
15,064,166 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a main form, on its header i placed a textFilter text box to search by reference number, transaction date, and part number.. reference number and transaction date are fields of main form, while part number is the field of sub fom.. i placed the following code behind txtFilter text box change event:
Private Sub txtFilter_Change()

 Dim sFind, sField, sFilter As String
    sFind = Nz(txtFilter.Text, "")
    If Len(sFind) > 0 Then
        Dim rsMe As Recordset
        Set rsMe = Me.Recordset
        Dim iFields, iField, iFieldsIncluded As Integer
        iFields = rsMe.Fields.count
        iFieldsIncluded = 0
        sFilter = ""
        For iField = 0 To iFields - 1
            sField = rsMe.Fields(iField).Name
            If rsMe.Fields(iField).type = dbText Then
                If iFieldsIncluded > 0 Then sFilter = sFilter & " Or "
                sFilter = sFilter & "[" & sField & "] Like '*" & sFind & "*'"
                iFieldsIncluded = iFieldsIncluded + 1
            End If
        Next iField
        Set rsMe = Nothing
        Me.Filter = sFilter
        Me.FilterOn = True
        Me.Filter = ""
        Me.FilterOn = False
    End If
    txtFilter.SelStart = Len(sFind) + 1
    txtFilter.SelLength = 0

End Sub

this code is only for main form search records.. plz help me to filter by part number as well.
Maciej Los 10-Apr-13 11:47am
What kind of application: Access, Excel, Word???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900