silentwolf
Well-known Member
- Joined
- May 14, 2008
- Messages
- 1,216
- Office Version
- 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.
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.
Would be nice if someone could help me with this problem please!
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
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