Results 1 to 4 of 4
  1. #1
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111

    Access Crashes When Looping Through a Recordset

    I'm currently developing a database and have a lot of test data in tables. Occasionally I'll need to change some of this test data, and to save time I'll create a loop to change data in my tables instead of manually going in and changing every value.



    The last few times I've tried this, Access has crashed.

    At first I thought it was because the Recordset I was changing had too many records (somewhere around the 100 - 200 range), but the latest occurrence of this issue only had 9 records to go through.
    I've tried using 'Do Until Recordset.EOF' and 'For i = 1 to #OfRecords' and gotten the same result.

    This is odd, because I have a few forms that use 'Do Until Recordset.EOF' in various events, and they're still working just fine. This has only happened when I create a new button and put the loop behind it with the intention of just deleting the button and the code once I've made the changes.

    Here's my latest attempt at this, which just crashed Access a few minutes prior to me posting this.
    It's probably worth noting that at first I was trying to change rs(3), (4), (5), (6), and (7), but after that crashed Access I lowered it to just rs(3) to see if that was the issue. All of these fields being changed are number fields, none of them are 0, and nothing will result in something being 0.

    Code:
    Dim var1 As Double, Rsize As Integer, db As Database, rs As Recordset
    
    Set db = Currentdb
    Set rs = db.OpenRecordset("tblName")
    
    
    Rsize = DLookup("size", "tRAMSize")
    
    rs.MoveFirst
    
    
    Do Until rs.EOF
        
        var1 = rs(3)
        
        var1 = var1 / 10
        
        var1 = var1 * Rsize
        
        var1 = Round(var1)
        
        rs.Edit
        rs(3) = var1
        rs.Update
        
        
        
    Loop

    Any help is greatly appreciated

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're in an endless loop because you don't have

    rs.MoveNext

    in the loop. The code just keeps changing the first record endlessly.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ItsRoland is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Posts
    111
    Oh wow. I can't believe I missed that.

    Thanks for the help

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 7
    Last Post: 08-26-2016, 07:45 AM
  2. Replies: 2
    Last Post: 10-31-2014, 07:42 AM
  3. looping through recordset (columnwise)
    By pradeep.sands in forum Queries
    Replies: 1
    Last Post: 06-27-2013, 09:46 AM
  4. Replies: 2
    Last Post: 06-13-2012, 06:00 PM
  5. Looping in Access
    By ducthang88 in forum Programming
    Replies: 2
    Last Post: 12-04-2010, 07:43 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