0

I'm running a database at work with only one user, and every time I run the below code when clicking an individual radio button it's giving me the message

The Data has been changed Another user has edited this record and saved the changes before you attempted to save your changes. Re-edit the record.

This message only comes up after click the button a second time; once clicking it a third time the value is changed.

Private Sub radioNECC10000_Click()

Dim SQL As String

DoCmd.SetWarnings False
If (IsNull(Me.VendorNum.Value)) Then
    MsgBox ("Please select a vendor!")
Else
    If (Me.radioNECC10000 = True) Then
        SQL = "UPDATE tbleVendorRecord " & _
                 "SET NECC_10000 = 10000 " & _
               "WHERE Vendor_ID = " & VendorNum & " "
        DoCmd.RunSQL SQL
    Else
        SQL = "UPDATE tbleVendorRecord " & _
                 "SET NECC_10000 = 0 " & _
               "WHERE Vendor_ID = " & VendorNum & " "
        DoCmd.RunSQL SQL
    End If
End If

End Sub
Maldred
  • 1,074
  • 4
  • 11
  • 33
  • 2
    Probably not related to issue but should set warnings back to True at end of procedure. Or use CurrentDb.Execute and won't have to bother with SetWarnings. Is radio button part of an option group that is bound to field? Is user entering data into record and then you are trying to run UPDATE on that same record? Commit user edits to table first. – June7 Sep 12 '17 at 20:45
  • I agree with June7, it's probably a problem with uncommited changes. It's likely the answer in the duplicate just works because a requery also commits changes, but there are more explicit ways of commiting changes (such as `DoCmd.RunCommand acCmdSaveRecord`) – Erik A Sep 12 '17 at 20:59
  • There is no user input; once the user clicks the radio button the query will run either one of those situations once depending on the status of the radio button (on or off). I will turn the warning messages back on, I just forgot to put that line in, thanks for the reminder! No it's not bound to any field either, it's just a button on it's own with a label beside it – Maldred Sep 12 '17 at 21:43

1 Answers1

0

Thanks to Ken White from an earlier post they found

Possible duplicate of "The data has been changed" error when stepping from main form into sub form

I tried adding the below code into the After Update field

Private Sub radioNECC10000_AfterUpdate()
    Me.Form.Requery
End Sub

Worked and is no longer providing me with that message

Maldred
  • 1,074
  • 4
  • 11
  • 33