By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,984 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,984 IT Pros & Developers. It's quick & easy.

How do I use Recordset.filter inside a loop

P: 2
I have an active recordset (created with an SQL statement) & I wish to use recordset.filter inside a loop, as each time I traverse the loop I want to filter for something different. How can I do this?
Nov 1 '12 #1

✓ answered by TheSmileyCoder

I don't know if that is doable, and whether you actually get any benefit from it. Another approach could be (Assuming you use DAO recordset which you forgot to specify) too use the FindFirst and FindNext methods



Expand|Select|Wrap|Line Numbers
  1. Dim rs as Dao.Recordset
  2. set rs=currentdb.openRecordset......
  3. Dim strFilter as string
  4. strFilter="ID_Author=" & 1
  5.  
  6. rs.FindFirst strFilter
  7. Do While not rs.Nomatch
  8.   'Your other code goes here
  9.  
  10.   rs.FindNext strFitler
  11. Loop

Share this Question
Share on Google+
6 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
I don't know if that is doable, and whether you actually get any benefit from it. Another approach could be (Assuming you use DAO recordset which you forgot to specify) too use the FindFirst and FindNext methods



Expand|Select|Wrap|Line Numbers
  1. Dim rs as Dao.Recordset
  2. set rs=currentdb.openRecordset......
  3. Dim strFilter as string
  4. strFilter="ID_Author=" & 1
  5.  
  6. rs.FindFirst strFilter
  7. Do While not rs.Nomatch
  8.   'Your other code goes here
  9.  
  10.   rs.FindNext strFitler
  11. Loop
Nov 1 '12 #2

NeoPa
Expert Mod 15k+
P: 31,492
The Filter property applies to the recordset as opened Deb. It isn't something you can change mid-stream without requerying the recordset.

Can you make your question clearer please, as it's hard to answer when you have to spend so much energy guessing what the question is really saying.
Nov 1 '12 #3

P: 1
***


Since Deb is talking about looping, seems to me the recordset would be requeried each time. That wasnt clear?
Apr 12 '13 #4

NeoPa
Expert Mod 15k+
P: 31,492
If it seems that way to you then I would suggest you don't have the experience to realise that we get thousands of requests for help which are not based on very sound logic or the most basic of understanding of the issues. Making assumptions about what the OP means is not generally a wise thing to do.

It is never sensible to ask questions without the purport of the question being made clear and explicit. That is why the site rules insist they are done in a way that doesn't waste everyone's time and energy responding with questions about what is actually meant.

I must admit that was always clear and obvious to me, but it's true that many need to go through the experience a few times before they realise why such questions are such a problem. In the mean time, we moderators are here to put people straight.

Thanks for your input.

PS. Clearly, in this case, to follow the implied logic of the question would be pretty silly indeed. I can imagine situations where that may be required, but none where that approach would make good sense. To advise in a case like this I'd need a proper understanding of what the OP thought she was asking about.
Apr 12 '13 #5

P: 2
Thanks for your reply. I found a solution by approaching the problem differently. As it was some time ago, I haven't got the details.I hope I haven't wasted anyone's time. I'm knew to posting stuff to forums.
I refer to this site a lot for help with Access VBA problems & find it most helpful. Keep up the great work.
Aug 16 '13 #6

zmbd
Expert Mod 5K+
P: 5,397
DebR (...)As it was some time ago, I haven't got the details.(...)
No, DebR, you didn't waste anyone's time.

(...)
This is exactly why we discourage posting into old threads unless the post has something really special to add.
Aug 16 '13 #7

Post your reply

Sign in to post your reply or Sign up for a free account.