Text box Formula Error Message

E

Eb1mom

I am using this function to calculate elapsed time. It
works very well if there are dates entered for date1 and
date2. If no dates or only one date is entered the text box
with formula will show ERROR. Dates are entered many hours
or sometimes days apart and users are confused by Error
message. I realize ERROR is correct because math functions
can not be performed on a null value. Is there any way I
can change error message to read "waiting for date entry"?


The formula in text box is "=getelapsedtime([date2]-[date1])"
This in Module
Function GetElapsedTime(interval)
Dim totalhours As Long, totalminutes As Long, totalseconds
As Long
Dim days As Long, hours As Long, Minutes As Long, seconds
As Long
days = Int(CSng(interval))
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
totalseconds = Int(CSng(interval * 86400))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
seconds = totalseconds Mod 60
GetElapsedTime = days & " Days " & hours & " Hours " &
Minutes & " Minutes " & seconds & " Seconds "
End Function
 
A

Alphonse Giambrone

Instead of
Function GetElapsedTime(interval)
'your code...

End Function

Use (air code):
Function GetElapsedTime(byval varDate2 as variant, byval varDate1 as
variant)

Dim interval as variant

If isNull(varDate1) or IsNull(varDate2) Then
GetElapsedTime = "Waiting For Date Entry"
Exit Function
Else
interval = varDate2 - varDate1
End If

'your code

End Function

Then your textbox control source becomes:
"=getelapsedtime([date2], [date1])"
 
E

eb1mom

Many Thanks Alphonse, Your code works great. Database users
will no longer be confused.

-----Original Message-----
Instead of
Function GetElapsedTime(interval)
'your code...

End Function

Use (air code):
Function GetElapsedTime(byval varDate2 as variant, byval varDate1 as
variant)

Dim interval as variant

If isNull(varDate1) or IsNull(varDate2) Then
GetElapsedTime = "Waiting For Date Entry"
Exit Function
Else
interval = varDate2 - varDate1
End If

'your code

End Function

Then your textbox control source becomes:
"=getelapsedtime([date2], [date1])"

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


I am using this function to calculate elapsed time. It
works very well if there are dates entered for date1 and
date2. If no dates or only one date is entered the text box
with formula will show ERROR. Dates are entered many hours
or sometimes days apart and users are confused by Error
message. I realize ERROR is correct because math functions
can not be performed on a null value. Is there any way I
can change error message to read "waiting for date entry"?


The formula in text box is "=getelapsedtime([date2]-[date1])"
This in Module
Function GetElapsedTime(interval)
Dim totalhours As Long, totalminutes As Long, totalseconds
As Long
Dim days As Long, hours As Long, Minutes As Long, seconds
As Long
days = Int(CSng(interval))
totalhours = Int(CSng(interval * 24))
totalminutes = Int(CSng(interval * 1440))
totalseconds = Int(CSng(interval * 86400))
hours = totalhours Mod 24
Minutes = totalminutes Mod 60
seconds = totalseconds Mod 60
GetElapsedTime = days & " Days " & hours & " Hours " &
Minutes & " Minutes " & seconds & " Seconds "
End Function


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top