DateDiff with if null then use prior time

DateDiff with if null then use prior time

我想在我的员工输入返回办公室的时间 [AActReturn0] 出现在字段 [AActDrive50] 中后计算最终驾驶时间,但如果 AActFinish5 为空,我需要它转到 AActFinsh4,但如果那是 null 我需要它来检查 AActFinish3,一直到 AActFinish1。我不确定我在这里做错了什么。我也试过 Dim。我不知道该怎么做。

尝试 #1:

Private Sub AActReturn0_AfterUpdate()

If AActFinish5 <> Null Then
    AActDrive50 = DateDiff("n", [AActFinish5], [AActReturn0])

ElseIf [AActFinish5] = Null Then
   AActDrive50 = DateDiff("n", [AActFinish4], [AActReturn0])

ElseIf [AActFinish4] = Null Then
   AActDrive50 = DateDiff("n", [AActFinish3], [AActReturn0])
   
ElseIf [AActFinish3] = Null Then
   AActDrive50 = DateDiff("n", [AActFinish2], [AActReturn0])

ElseIf [AActFinish2] = Null Then
   AActDrive50 = DateDiff("n", [AActFinish1], [AActReturn0])

End If

End Sub

尝试 #2:

Private Sub AActReturn0_AfterUpdate()
Dim Final As String

If AActFinish5 <> Null Then Final = AActFinish5
If Final = Null Then Final = AActFinish4
If Final = Null Then Final = AActFinish3
If Final = Null Then Final = AActFinish2
If Final = Null Then Final = AActFinish1

AActDrive50 = DateDiff("n", [Final], [AActReturn0])
End Sub

您可以使用 Nz:

Private Sub AActReturn0_AfterUpdate()

    Dim Final   As Date

    Final = Nz(AActFinish5, Nz(AActFinish4, Nz(AActFinish3, Nz(AActFinish2, Nz(AActFinish1)))))

    AActDrive50 = DateDiff("n", [Final], [AActReturn0])

End Sub