filter listfield question :(

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi all I have a access form 07 Single form wich shows me all projekts.
Also I included a listfield in the same form.
So far so good :)
In the form header I inserted a textbox wich filters me the projects.
Therefor I includet a modul.
Code:
Function SearchAllFieldsFilter(strTable As String, strSearch As String) As String

  Dim rs As Recordset, intCnt As Integer

  Dim strFilter As String, I As Integer

    intCnt = 0

  Set rs = CurrentDb.OpenRecordset(strTable)

  rs.MoveFirst

  With rs

    For I = 0 To .Fields.Count - 1

      If .Fields(I).Type = dbText Or .Fields(I).Type = dbMemo Then

        intCnt = intCnt + 1
        strFilter = strFilter & _
                   "[" & .Fields(I).Name & "] like '*" & _
                   strSearch & "*' or "

      End If

    Next I

  End With

  rs.Close

  If intCnt > 0 Then

    'letztes " or " wieder raus

    strFilter = Left$(strFilter, Len(strFilter) - 4)

    SearchAllFieldsFilter = strFilter

  Else

    SearchAllFieldsFilter = ""

  End If

End Function
This codes allows me to filter all fields! And it works fine.
However can I change this code so it also filters the list field "lstProjekt"
The code to filter the form is below.
Code:
Private Sub txtSearch_AfterUpdate()
  Dim strSearch As String, strFilter As String

  strSearch = Me.txtSearch

  If strSearch = "*" Then

    Me.Filter = ""

    Me.FilterOn = False

    Exit Sub

  End If
 

  strFilter = SearchAllFieldsFilter("tblProjekte", Me.txtSearch)

  If strFilter <> "" Then

    Me.Filter = strFilter

    Me.FilterOn = True

  End If


End Sub
Would be nice if someone could help me with this problem please!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Albert

How did you populate the 'listfield' control?
 
Upvote 0
Hi Norie,
thanks for your reply but I guess I don't need it anymore I changed it to a split form and it works fine :)
Sorry that I did not write that before!!
Cheers :)
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,741
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top