Set rsTemp = mRsOriginalList.OpenRecordset(dbOpenDynaset)
rsTemp.Filter = StrFilter
Set rsTemp = rsTemp.OpenRecordset
tothere are times where this makes coding easier
Changing the rowsource as you show is definitely easier, less code, and less prone to issues like this.there are times where this makes coding easier. But this is not one of those times.
I never used Requery.?Definitely over-engineered using a recordset in this instance!
Using dynamic SQL and perhaps a DCount() first to check how many records would be returned would be much simpler.
Interesting to note that you need to Requery after setting the the .Recordset = Nothing to remove the previous results
No, MajP did.I never used Requery.?
So one would imagine, but it seems a shortcoming of Access implementation here when using a DAO.Recordset object that it doesn't mimic the long-understood behaviour when changing a listbox's .RowSourceIn fact my understanding, is that when you change the recordset, an implcit requery happens as it gets the new recordset?
Have you tried this situation?Making the Row Source an empty string is a standard way of clearing the content of the listbox/combobox. It does not matter whether the Row Source is a value list or a query. I have not yet encountered a situation where it would not work.
Best,
Jiri
Bottom line if you use a Rowsource, Access will create the recordset based on the Rowsource. The recordset and the rowsource will always be "in synch."I've a listbox on a form which is populated with the RecordSet of a DAO query.
To be fair the OP kind of lead us astray because it was not clear or common to populate VIA CODE the recordset of the listbox. But this does highlight an issue if you do populate the recordset via code.
To be fair, the OP did in the above statement try and explain what was happening. Mostly, whether through ignorance or disbelief that anyone would use a recordset object to set a listbox contents, everyone assumed that wasn't the case.I've a listbox on a form which is populated with the RecordSet of a DAO query.
In post 38 I did row, then recordset and it worked for me.To be fair the OP kind of lead us astray because it was not clear or common to populate VIA CODE the recordset of the listbox. But this does highlight an issue if you do populate the recordset via code.
Bottom line if you use a Rowsource, Access will create the recordset based on the Rowsource. The recordset and the rowsource will always be "in synch."
If you populate the listbox by setting the Recordset you can get the rowsource and recordset "out of synch".
So basically you have to change both the recordset and the rowsource. Setting the recordset to nothing or setting the rowsource to "" does not work. You have to do both and in the correct order.
You can play with the demo to see.
So @Solo712 can now clearly see a situation where making the row source an empty string does not clear the list.
View attachment 103979
So bind the listbox to the Recordset.
Setting rowsource to "" does not clear
Setting recordset to Nothing does not clea
Setting the rowsource to "" then recordset to nothing does not work but Vice Versa does
Setting the rowsource to "" then requerying the list does not work
Just to be clear you do understand that everyone agrees there is no issue when setting the rowsource in code? And you are not going to see this behavior if you do. The issue only arises setting the Recordset directly.but it's not the behaviour I see. My listbox properties are: Control Source: empty, RowSource, empty, RowSourceType: Table/Query. RowSource is set in code, list populates, and when I set the RowSource to "", the list box clears. It's that simple.