Access VBA recordset Update runs fine but not updating

3.2k Views Asked by At

I am having trouble figuring out what is wrong with my code. Mind you, the code was working fine all along until last week. We haven't made any changes to the code... so this is a mystery.

I have an Access VBA to update a record by incrementing by 1 by using recordset.update. The code looks something like this...

Sub UpdateQuarter(PersonName As String)
Dim dB As Database
Dim rst As DAO.Recordset
Dim Quarter As Integer

Set dB = CurrentDb
Set rst = db.OpenRecordset("table")

rst.MoveFirst
Do Until rst.EOF
    rst.Edit
    If Name = rst!NameofPerson Then
        Quarter = rst!CurrentQuarter
        Quarter = Quarter + 1
        rst!CurrentQuarter = Quarter
        rst.Update
    End If
    rst.MoveNext
Loop
rst.Close
Set rst = Nothing

End Sub

I have other Access database with very similar code (exact same structure) running perfectly fine. This code ALSO runs perfectly fine, and when I debug line by line, it shows that the correct values are being captured and incremented. However, it doesn't update the table!!

This is driving me crazy. Anyone have insight as to why this may occur??

Thanks in advance.

1

There are 1 best solutions below

0
On

You have to manually open your database and Ctrl+S and close it. The SQL qwery will work after that.

And then won't work again. Repeat step one...