I'm sorry that I messed you up with more options than you asked.
If I don't get you wrong you need a switch between to filters, or filter and
absence of it. Right?
What I don't understand is if you already have the control to toggle and
what are you going to filter. I though you want it for the listbox34.
I'm going to suppose that you have a form, a toggle control named
ToggleFilter, and a listbox named Listbox34, and if you leave the toggle
button down (=true) that means that the filter is on and the Listbox34 will
only shows the active records. Caption the ToggleFilter to "Filter off"
Private Sub ToggleFilter_AfterUpdate()
Dim strFilterOn, strFilterOff as String
' Bring only Active records
strFilterOn = "SELECT [Name List].ID, [Name List].TID, " & _
"[Name List].LastName, [Name List].FirstName, " & _
"[Name List].Status FROM [Name List] " & _
" WHERE ((([Name List].Inactive)= False) " & _
"ORDER BY [Name List].LastName, [Name List].FirstName "
'Bring all
strFilterOff = "SELECT [Name List].ID, [Name List].TID, " & _
"[Name List].LastName, [Name List].FirstName, " & _
"[Name List].Status FROM [Name List] " & _
"ORDER BY [Name List].LastName, [Name List].FirstName "
If ToggleFilter then
List34.RowSource=strFilterOn
ToggleFilter.Caption="Filter on"
Else
List34.RowSource=strFilterOff
ToggleFilter.Caption="Filter off"
End If
End Sub
lmv said:
Thank you ... I have tried to get this to work but I can't figure it out
The listbox is based on inactive=false
I just need it to toggle between "false" and "is not null"
If I could see the inactive= true it would be ok but not necessary
But I can't get the code to work it doesn't toggle between the 3 cases. I
have tried as many combinations as I can think of but still isn't working.
Have the button named "Active" but this is how the list loads so I really
just need it to go between ACTIVE and ALL.... this is what I tried using
your code.
Private Sub btnActiveFilter_Click()
Dim strFilterOnA, strFilterOnI, strFilterOff As String
'Bring active
strFilterOnA = "SELECT [Name List].ID, [Name List].TID, [Name
List].LastName, " & _
"[Name List].FirstName, [Name List].Status FROM [Name List] " & _
" WHERE ((([Name List].Inactive)=False)) " & _
"ORDER BY [Name List].LastName, [Name List].FirstName "
' Bring only inactive records
strFilterOnI = "SELECT [Name List].ID, [Name List].TID, [Name
List].LastName, " & _
"[Name List].FirstName, [Name List].Status FROM [Name List] " & _
" WHERE ((([Name List].Inactive)= True) " & _
"ORDER BY [Name List].LastName, [Name List].FirstName "
'Bring all
strFilterOff = "SELECT [Name List].ID, [Name List].TID, [Name
List].LastName, " & _
"[Name List].FirstName, [Name List].Status FROM [Name List] " & _
" WHERE ((([Name List].Inactive)= Is Not Null) " & _
"ORDER BY [Name List].LastName, [Name List].FirstName "
Select Case btnActiveFilter.Caption
Case "Active"
List34.RowSource = strFilterOnA
List34.Requery
btnActiveFilter.Caption = "Active"
Case "Inactive"
List34.RowSource = strFilterOnI
List34.Requery
btnActiveFilter.Caption = "InActive"
Case "All"
List34.RowSource = strFilterOff
List34.Requery
btnActiveFilter.Caption = "All"
End Select
End Sub