更改字段时更新另一个 table

Update another table when field is changed

我有一个包含 "DateProduced" 字段的表单。绑定到它的 table 称为 "Report"。

我尝试将更新事件添加到此字段,并希望此事件更新数量 table 中的 "DateProduced" 字段(如果两者的 ID 都匹配)。

Me![Text0] 显示报告字段中的 ID

Me![Text4] 显示 DateProduced from Report 字段。

活动代码如下

Private Sub Text4_AfterUpdate()
Dim strSQL As String

strSQL = "UPDATE Quantity " _
& "SET [DateProduced] = (#" & Me![Text4] & "#) " _
& "WHERE ID = (" & Me![Text0] & ")"

DoCmd.RunSQL strSQL
End Sub

但是我做不到。

我用下面的代码让它工作。感谢

Private Sub Text4_Exit(Cancel As Integer)
Dim strSQL As String
strSQL = "UPDATE Quantity " _
& "SET [DateProduced] = #" & Format(Me.Text4.Value, "dd-mm-yyyy") & "#" _
& "WHERE [ID] = (" & Me![Text0] & ");"

DoCmd.RunSQL strSQL

End Sub

对于 dd/mm 可以互换为有效日期的值,该日期格式将失败。它应该是:

Private Sub Text4_Exit(Cancel As Integer)

    Dim strSQL As String

    strSQL = "UPDATE Quantity " _
    & "SET [DateProduced] = #" & Format(Me!Text4.Value, "yyyy\/mm\/dd") & "# " _
    & "WHERE [ID] = " & Me![Text0].Value & ";"

    DoCmd.RunSQL strSQL

End Sub

注意:Text0等的名字应该改成有意义的名字。