Using the following code on the click event of a command button on a form to filter a list box based on the AcctStatus field that is displayed in the list box.
What modification(s) is/are necessary to enable a filter on any field within the listbox?
Also, is it possible to have multiple textboxes and be able to perform a filter and subfilter on the contents of a listbox - sort of like a sort and subsort function within MS Excel?
Appreciate any additional thoughts regarding the filtering of a listbox using textboxes or another more preferred method.
Private Sub Command116_Click()
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
strSQL = "SELECT tblData.Product, tblData.AcctStatus FROM tblData"
strWhere = "WHERE"
strOrder = "ORDER BY tblData.Product, tblData.AcctStatus;"
If Not IsNull(Me.Text114) Then
strWhere = strWhere & " (tblData.AcctStatus) Like '*" & Text114 & "*' AND"
End If
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
Me.List84.RowSource = strSQL & " " & strWhere & "" & strOrder
Me.Text117 = Me.List84.ListCount - 1
If (Me.List84.ListCount = 0) Then
Me.Text117 = 0
End If
What modification(s) is/are necessary to enable a filter on any field within the listbox?
Also, is it possible to have multiple textboxes and be able to perform a filter and subfilter on the contents of a listbox - sort of like a sort and subsort function within MS Excel?
Appreciate any additional thoughts regarding the filtering of a listbox using textboxes or another more preferred method.
Private Sub Command116_Click()
Dim strSQL As String, strOrder As String, strWhere As String
Dim dbNm As Database
Dim qryDef As QueryDef
Set dbNm = CurrentDb()
strSQL = "SELECT tblData.Product, tblData.AcctStatus FROM tblData"
strWhere = "WHERE"
strOrder = "ORDER BY tblData.Product, tblData.AcctStatus;"
If Not IsNull(Me.Text114) Then
strWhere = strWhere & " (tblData.AcctStatus) Like '*" & Text114 & "*' AND"
End If
strWhere = Mid(strWhere, 1, Len(strWhere) - 5)
Me.List84.RowSource = strSQL & " " & strWhere & "" & strOrder
Me.Text117 = Me.List84.ListCount - 1
If (Me.List84.ListCount = 0) Then
Me.Text117 = 0
End If