Results 1 to 7 of 7
  1. #1
    JAPA1972 is offline Novice
    Windows 7 32bit Access 2016
    Join Date
    Jan 2019
    Posts
    14

    Thumbs up Findnext method and End of Recordset

    I am implementing search functionality with the findnext/findfirst method. I want the search to finish when the end of the recordset has been reached. The below code, "loop while rs.EOF = false" statement, won't work. For the sake of simplicity I am not including the findfirst section of the code. What am I missing here?




    Dim rs As dao.Recordset

    Set frm = Forms!frmMyForm
    Set rs = frm.RecordsetClone

    do
    rs.findnext "[FIELDNAME] LIKE '*StringToBeSearched*' 'this works okay

    If rs.NoMatch = False Then
    Forms!frmalldams.Bookmark = rs.Bookmark
    End If

    loop while rs.EOF = false 'this never works. rs.EOF is always false
    'even though access starts at the first record when the end is reached

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Not much there to go on, but I think you want
    Do Until rs.EOF
    do stuff
    Loop
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

  4. #4
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Shouldn't there also be a rs.MoveNext before the Loop?? (routinely forget to add it )

    Code:
    Do Until rs.EOF
       do stuff
       rs.MoveNext
    Loop

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Quote Originally Posted by ssanfu View Post

    Shouldn't there also be a rs.MoveNext before the Loop?? (routinely forget to add it )

    Code:
    Do Until rs.EOF
       do stuff
       rs.MoveNext
    Loop
    See "Do stuff" . That was meant to cover everything, including a move as it's entirely possible it is in the code that could have been posted but wasn't.

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,388
    I hate it when developing and I forget to add the .MoveNext, then run the code. Computer goes into a hard loop and nothing will break it out except ending Access with task manager. Then to top it off, if I haven't saved in Access before running, I lose the code!

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Then to top it off, if I haven't saved in Access before running, I lose the code!
    Having been bitten that way at least 2x I NEVER test code without FIRST saving THEN compiling. A compile can cause Access to crash, which is why my save comes first. To top it off, most times if I'm looping through a recordset I step through the code until the loop performs as expected. Has saved me from having to deep-six Access more than once, and yes, because of a missing MoveNext.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 01-07-2015, 06:21 PM
  2. Replies: 1
    Last Post: 12-05-2014, 07:41 PM
  3. recordset clone method
    By vientito in forum Programming
    Replies: 1
    Last Post: 10-30-2014, 11:33 PM
  4. Use "FindNext" Method in KML Text File
    By JonMulder in forum Programming
    Replies: 0
    Last Post: 02-08-2013, 12:59 PM
  5. rs.FindNext vs. rs.MoveNext
    By jgelpi16 in forum Programming
    Replies: 4
    Last Post: 02-04-2011, 03:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums