Microsoft Access子表单写入冲突问题

时间:2013-01-03 05:46:35

标签: ms-access access-vba ms-access-2010 conflict

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

所以我所做的是为表格和子表单中的每个可编辑文本框或组合框我做了它,以便他们在BeforeUpdateAfterUpdate事件中有活动。

例如我的文本框的BeforeUpdate:

Private Sub textbox_BeforeUpdate(Cancel As Integer)
    If Not isValidUser Then
        Cancel = True
        Me.textbox.Undo
    End If
End Sub

我的AfterUpdate是:

Private Sub textbox_AfterUpdate()
    updateRecord Me.textbox.Value, UserNameWindows
End Sub

和updateRecord是:

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

好的现在是奇怪的事情,当我对Main窗体中的控件进行修改时,这完全正常,但是只要尝试改变子窗体中的某些内容就会引发写冲突。

如果我选择保存记录,它会忽略我的代码以更新最后修改过的人以及何时我选择放弃更改它会运行我的代码并更新它已更改它!

任何人都知道出了什么问题或更好的方法吗?

0 个答案:

没有答案