Results 1 to 3 of 3
  1. #1
    sukhjinder's Avatar
    sukhjinder is offline Beginner
    Windows 10 Access 2016
    Join Date
    May 2016
    Posts
    43

    Record not edited by using the code

    this code is not editing the record in the table

    Private Sub cmdclick_Click()


    Set db = CurrentDb
    Set rs = db.OpenRecordset("tbl_camd")
    For i = 0 To rs.RecordCount - 1
    If rs.Fields("mainID_PK") = Me.cbomslno Then
    rs.Edit
    rs!ifmdate = Me.txtdate
    rs.Update
    End If

    Next
    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,518
    Far more efficient to use an update query. Your code would need to move the recordset, which it doesn't do. The normal loop would look like:

    Code:
    Do While Not rs.EOF
      'your code
      rs.MoveNext
    Loop
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    And if it wasn't clear, my point is that

    If rs.Fields("mainID_PK") = Me.cbomslno Then

    is always checking the first record in the table. But again, an update query would be far more efficient.
    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. Edited Record Lock?
    By mrmims in forum Forms
    Replies: 1
    Last Post: 09-01-2016, 03:55 PM
  2. Lock form to the record being edited
    By joecamel9166 in forum Forms
    Replies: 3
    Last Post: 03-24-2016, 03:09 PM
  3. close a form if record is open and being edited
    By Ruegen in forum Programming
    Replies: 9
    Last Post: 08-15-2014, 01:36 AM
  4. creating an edited record report
    By mike02 in forum Access
    Replies: 4
    Last Post: 06-13-2013, 08:36 AM
  5. Replies: 9
    Last Post: 05-12-2012, 12:16 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