If Null Set Value

  • Thread starter Thread starter LB
  • Start date Start date
L

LB

I am trying to calculate how long something has been out of service.
I can calculate the time using datediff is the item is back in service
but i would like to calculate the time thus far if it's still out of
service. I was thinking something like:
Private Sub duration()
If Me!In_Service_Date IS NULL Then
Me!Duration = DateDiff(h", [VEHICLE_OS_DATE], [Now()])
Else
End Sub

Any ideas. I'm trying to put this code in the report itself (VB) but
I don't seem to be getting anywhere. Any help would be appreciated.

LB
 
LB,
I run a report that lists the number of days that a
proposal is open. I calculate the days in a query that has
an expression "OpenProp: Date()-[Date Completed]". This
works great, hopefully you can use.

Sky
 
I am trying to calculate how long something has been out of service.
I can calculate the time using datediff is the item is back in service
but i would like to calculate the time thus far if it's still out of
service. I was thinking something like:
Private Sub duration()
If Me!In_Service_Date IS NULL Then
Me!Duration = DateDiff(h", [VEHICLE_OS_DATE], [Now()])
Else
End Sub

Any ideas. I'm trying to put this code in the report itself (VB) but
I don't seem to be getting anywhere. Any help would be appreciated.

LB

If you must use code, then:
Private Sub duration()
If IsNull(Me![In_Service_Date]) Then
Me!Duration = DateDiff("h", [VEHICLE_OS_DATE], Now)
Else
Me!Duration = DateDiff("h", [VEHICLE_OS_DATE], [In_Service_Date])
End Sub

If you wish to simply use a control on the report, then, as it's
control source, write:

=IIf(IsNull([In_Service_Date]),DateDiff("h", [VEHICLE_OS_DATE],
Now()),DateDiff("h", [VEHICLE_OS_DATE], [In_Service_Date]))

Note: the VBA code can use the Me! keyword, and the Now() function
does not need the parentheses.
The Access Control Source can NOT use Me! and the Now() function MUST
use the parentheses.
In either case, the Now function can not be within brackets, as it is
not a field name, and the "h" in the function must include both
quotes. You left off the first one.
 
Back
Top