How do I use Recordset.filter inside a loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DebR
    New Member
    • Nov 2012
    • 2

    How do I use Recordset.filter inside a loop

    I have an active recordset (created with an SQL statement) & I wish to use recordset.filte r inside a loop, as each time I traverse the loop I want to filter for something different. How can I do this?
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    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



    Code:
    Dim rs as Dao.Recordset
    set rs=currentdb.openRecordset......
    Dim strFilter as string
    strFilter="ID_Author=" & 1
    
    rs.FindFirst strFilter
    Do While not rs.Nomatch
      'Your other code goes here
    
      rs.FindNext strFitler
    Loop

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      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.

      Comment

      • maxhadden
        New Member
        • Apr 2013
        • 1

        #4
        looping thru recordsets

        ***


        Since Deb is talking about looping, seems to me the recordset would be requeried each time. That wasnt clear?
        Last edited by NeoPa; Apr 12 '13, 07:49 PM. Reason: No need to quote the previous post in full.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          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.
          Last edited by NeoPa; Apr 12 '13, 07:47 PM.

          Comment

          • DebR
            New Member
            • Nov 2012
            • 2

            #6
            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.

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              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.

              Comment

              Working...