mardi 11 août 2020

DateDiff with if null then use prior time

I want to get the final driving time to be calculated once my employee enters the time returning to office [AActReturn0] to appear in field [AActDrive50] but if AActFinish5 is null I need it to go to AActFinsh4, but if that is null I need it to check AActFinish3, all the way to AActFinish1. I am not sure what I am doing wrong here. I've also tried Dim. I'm at a loss how to do this.

Attempt #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

Attempt #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

Aucun commentaire:

Enregistrer un commentaire