Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms access Microsoft Access子窗体写入冲突问题_Ms Access_Vba_Ms Access 2010_Conflict - Fatal编程技术网

Ms access Microsoft Access子窗体写入冲突问题

Ms access Microsoft Access子窗体写入冲突问题,ms-access,vba,ms-access-2010,conflict,Ms Access,Vba,Ms Access 2010,Conflict,我有一个表单,其中包含一个子表单,该子表单显示链接到我的一个表的可编辑字段。对于我目前正在进行的一个项目,其中一个要求是我必须跟踪记录最后一次更改的时间以及更改的人 因此,我所做的是针对表单和子表单中的每个可编辑文本框或组合框,以便它们在更新前和更新后事件中都有事件 例如,文本框的my BeforeUpdate: Private Sub textbox_BeforeUpdate(Cancel As Integer) If Not isValidUser Then Canc

我有一个表单,其中包含一个子表单,该子表单显示链接到我的一个表的可编辑字段。对于我目前正在进行的一个项目,其中一个要求是我必须跟踪记录最后一次更改的时间以及更改的人

因此,我所做的是针对表单和子表单中的每个可编辑文本框或组合框,以便它们在更新前和更新后事件中都有事件

例如,文本框的my BeforeUpdate:

Private Sub textbox_BeforeUpdate(Cancel As Integer)
    If Not isValidUser Then
        Cancel = True
        Me.textbox.Undo
    End If
End Sub
我的后续更新是:

Private Sub textbox_AfterUpdate()
    updateRecord Me.textbox.Value, UserNameWindows
End Sub
更新记录是:

Public Sub updateRecord(bucNumber As String, updater As String)

    Dim Dbs As Object
    Dim rst As Object
    Dim fldEnumerator As Object
    Dim fldColumns As Object

    sqlStatement = "SELECT fName " & _
                        "FROM t_Staff " & _
                        "WHERE uName='" & updater & "';"

    'Getting fullname of user via username
    Set rst = CurrentDb.OpenRecordset(sqlStatement)

    'Setting fullname to updater variable
    updater = rst(0)

    'Clean Up
    Set rst = Nothing

    'Opening Bucket Contents
    Set Dbs = CurrentDb
    Set rst = Dbs.OpenRecordset("Bucket Contents")
    Set fldColumns = rst.Fields

    'Scan the records from beginning to each
    While Not rst.EOF
        'Check the current column
    For Each fldEnumerator In rst.Fields
        'If the column is named Bucket No
        If fldEnumerator.Name = "Bucket No" Then
            'If the Bucket No of the current record is the same as bucketNumber
                If fldEnumerator.Value = bucNumber Then
                    'Then change the updated fields by updater and todays date
                    rst.Edit
                    rst("Last Updated By").Value = updater
                    rst("Last Updated On").Value = Date
                    rst.Update
                End If
            End If
        Next
        'Move to the next record and continue the same approach
        rst.MoveNext
    Wend

    'Clean Up
    Set rst = Nothing
    Set Dbs = Nothing
End Sub
好吧,现在是一件奇怪的事情,当我修改主窗体中的控件时,它完全可以正常工作,但是一旦试图修改子窗体中的某些内容,它就会引发写入冲突

如果我选择保存记录,它将忽略我的代码,以更新上次修改它的人,以及何时和如果我选择放弃更改,它将运行我的代码并更新它,以确认它已被更改


有人知道哪里不对,或者有更好的方法吗?

一旦从表单移动到子表单,或者从子表单移动到子表单,记录就会被保存,因此任何更新事件都会运行。您可能希望查看到的评论中的链接。在大多数情况下,我在每个用户可编辑表中都包含CreatedDate、CreatedBy、LastUpdateDate、LastUpdatedBy字段?我已经研究过这种审计方法,如果不成功,我可能会转而使用这种方法。