“The data has been changed” error when stepping from main form into sub form

后端 未结 3 1266
遇见更好的自我
遇见更好的自我 2021-01-12 02:30

I\'m migrating an Access database to SQL Server using the SQL Server Migration Assistant (SSMA). The Access application will continue to be used but with linked tables inst

相关标签:
3条回答
  • 2021-01-12 02:32

    I solve this problem via writing AfterUpdate form-event like this:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
        cSQL = "update UnderlinedTable set Field1=" & Me.Controls("Field1") & _
            ", Field2=" & Me.Controls("Field2") & _ ' and all other fields in your form
            " where PrimaryKey=" & Me.Recordset.Fields("PrimaryKeyField")
        ' here command to SQL server that executes this cSQL string
        Me.Requery
        Cancel = True 'stop Access updating
    end sub
    

    It is possible to be wriiten universal BeforeUpdate form-event function that generates automatically Update statement based on form.recordsource and changed form fields that can be invoked from all AfterUpdate form-events passing form as parameter. I have made this for me.

    0 讨论(0)
  • 2021-01-12 02:41

    After much trial and error I solved the issue. In the enter event handler for the sub form control on the main form, I requeried the sub form itself.

    eg On the main form:

    Private Sub Subform1_Enter()
        Me.Subform1.Form.Requery
    End Sub
    

    I don't know why this works, only that it does.

    0 讨论(0)
  • 2021-01-12 02:53

    This happens when a record is updated in a table, but the record source of the main form has not been refreshed to reflect the change, so Access gets conflicting information and thinks the record has been changed. See also: http://support.microsoft.com/kb/302492

    0 讨论(0)
提交回复
热议问题