Results 1 to 4 of 4
  1. #1
    jax1000rr is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    26

    Question Loop function not moving to next record

    Hi,

    I am having issue with the below code editing the record, updating then moving to the next record. It only updates the first record in the Recordset. Is there anything in the syntax I missed?

    Code:
    Private Sub btnSave_Click()
    Dim r As DAO.Recordset
    Set r = CurrentDb.OpenRecordset("SELECT * FROM FilterCancellationReview")
    'Check to see if the recordset actually contains rows
    If Not r.BOF Then
        r.MoveFirst
        Do Until r.EOF = True
            'Perform an edit
            r.Edit
                    
            If Me.HMDADisposition = "Approved" Then
            If Me.HMDAApprovedStatus = "HANA" Or Me.HMDAApprovedStatus = "HANT" Or Me.HMDAApprovedStatus = "HCAN" Or Me.HMDAApprovedStatus = "HCLO" Or Me.HMDAApprovedStatus = "HREN" Or Me.HMDAApprovedStatus = "HUWD" Then
            Me.CurrentWF = APPR()
            Me.DateComplianceReviewed = Now
            Me.ComplianceReviewed = True
            End If
            End If
            If Me.HMDADisposition = "Declined" Then
            If Len(Me.RequestorNotes) > 5 Then
            Me.CurrentWF = DECL()
            Me.DateComplianceReviewed = Now
            Me.ComplianceReviewed = True
            End If
            End If
            If Me.HMDADisposition = "Duplicate" Then
            Me.CurrentWF = NOTF()
            Me.DateComplianceReviewed = Now
            Me.ComplianceReviewed = True
            End If
            If Me.HMDADisposition = "No Change" Then
            Me.CurrentWF = NOTF()
            Me.DateComplianceReviewed = Now
            Me.ComplianceReviewed = True
            End If
            
            r.Update
            'Move to the next record. Don't ever forget to do this.
            r.MoveNext
        Loop
     
    End If
    MsgBox "Changed have been saved."
    r.Close
    Set r = Nothing
    'DoCmd.Requery
    End Sub


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You aren't editing the recordset, you're editing the form. Editing the recordset would look like:

    r!FieldName = Whatever
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jax1000rr is offline Novice
    Windows XP Access 2007
    Join Date
    Apr 2012
    Posts
    26
    Quote Originally Posted by pbaldy View Post
    You aren't editing the recordset, you're editing the form. Editing the recordset would look like:

    r!FieldName = Whatever
    That makes perfect sense and worked great, TY.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    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: 5
    Last Post: 10-08-2012, 12:05 PM
  2. Error loop when I misscode in a function?
    By stumped in forum Programming
    Replies: 5
    Last Post: 09-27-2012, 01:25 AM
  3. Replies: 3
    Last Post: 09-19-2012, 07:34 AM
  4. Moving a record.
    By Cutter596 in forum Queries
    Replies: 1
    Last Post: 08-02-2011, 02:49 PM
  5. Loop until last record in excel table
    By compooper in forum Programming
    Replies: 5
    Last Post: 06-30-2011, 02:14 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