0

i try to update multiple records in a table using the subsequent code

when I press the button, the code runs perfectly and updates the records. the funny think happens when i close the form. Then, the first record of the table changes.

Probably, i miss something :(

"Private Sub cmdChange_Click()

Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sqlstrQuarantors As String
Dim i As Integer
i = 0

Dim Guarantor As String
Dim NumofGuarantors As Integer

Set db = CurrentDb

sqlstrQuarantors = " Select * from tblguarantors where GuarantorId = '" & Me.GuarantorId.Value & "'"
Set rst = db.OpenRecordset(sqlstrQuarantors)

   
Do While Not rst.EOF
If rst!GuarantorId = Me.GuarantorId.Value Then
        rst.Edit
        rst!GuarantorName = Me.GuarantorName.Value
        rst.Update
        i = i + 1
End If
rst.MoveNext
Loop

rst.Close

End Sub "

Yannis
  • 1
  • 1
  • Make sure you have the right kind of [DAO recordset](https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/recordset-object-dao). In this case you could also just issue an update command as an alternative to looping through a recordset. – topsail Jan 16 '23 at 21:47

0 Answers0