设置计算日期字段和当前日期时间差异的计算字段(Now 函数)

Set Calculated field that calculates difference of a date field and current datetime (Now function)

我有 3 个字段:[CreatedDateTime][ClosedDateTime][TAT]
CreatedDateTime 的默认值是 =Now() 因此每次添加新记录时都会使用当前 datetimestamp.

现在第 3 个字段需要包含 运行 周转时间。
虽然 CloseDateTime 仍然是空的,但它应该包含 Now()[CreatedDateTime] 字段的差异。否则它应该包含 [ClosedDateTime][CreatedDateTime].

的区别

我尝试使用 计算字段 类型,但它不允许 Now() 作为函数。
所以我尝试 Before Change 事件 Set FieldValue 字段 :[=21 上使用以下公式=]

IIF([ClosedDateTime]="",Now()-[CreatedDateTime],[ClosedDateTime]-[CreatedDateTime])

它接受公式但我得到一个错误:

Field Cannot be Update

在我尝试其他任何事情之前,有没有办法在 Access 中执行此操作?
或者也许有更简单的解决方案?

计算字段 in tables 是一个相当无用的概念。参见 http://allenbrowne.com/casu-14.html

解决方案是:创建一个 查询 ,在其中添加计算字段,公式可以正常工作,然后使用查询而不是 table在任何需要 TAT 字段的地方。

使用文本框通过此 ControlSource:

计算和显示 TAT
=Nz([ClosedDateTime],Now())-[CreatedDateTime]