Clearing Listbox filter (1 Viewer)

rayape

Registered User.
Local time
Today, 09:43
Joined
Dec 12, 2012
Messages
56
Hello, I have the following code to filter a listbox based on a combo box selection. I need a separate button that can clear the filter and display all records. I don't know how to do. Need help from learned members here. Thanks.

This filters the listbox based on the combo box selection .

Option Compare Database
Dim strListSource As String

Private Sub Combo47_AfterUpdate()
If Me.Combo47.ListIndex < 0 Then
Me.List29.RowSource = strListSource & ";"
Else
Me.List29.RowSource = strListSource & " WHERE tbl_Products.PlantID = " & Me.Combo47
End If
Me.List29.Requery
End Sub

Private Sub Form_Load()
strListSource = Replace(Me.List29.RowSource, ";", "")
End Sub
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:43
Joined
Oct 29, 2018
Messages
21,467
Hi. You'll need to store the original RowSource somewhere, so you can recall it later. Maybe you can use a TempVar.
 

cheekybuddha

AWF VIP
Local time
Today, 20:43
Joined
Jul 21, 2014
Messages
2,276
Hi,

In the button click event use:
Code:
  Me.List29.RowSource = strListSource

You don't need to requery the listbox - setting its RowSource does it implicitly.
 

rayape

Registered User.
Local time
Today, 09:43
Joined
Dec 12, 2012
Messages
56
@cheekybuddha - worked like a charm! Thanks.
@theDBguy - thanks again for helping.

Unrelated question: how do you folks and others in this forum know so much about Access? Is it just building a lot of applications? Is it studying books? What study material would you recommend for a beginner?
 

Users who are viewing this thread

Top Bottom