Creating a new function- Bad Mojo

  • Thread starter Thread starter Phil Lefter
  • Start date Start date
P

Phil Lefter

Once again my dance with Access Visual Basic is not leaving me very happy.
I am trying to create a function which will yield the elapsed time between 2
dates/times. I have downloaded the code for the GetElapsedTime function in
the Microsoft Knowledge base.
Per my understanding on how to do this task and by following the
instructions in "Building Applications in Access 97" and the Microsoft
Knowledge base I have input the code into a module 8 times.
Each time I try to use the function, I get one of 2 error boxes. If I use
the function in a report, the first prompts me for the GetElapsedTime
parameter. If I use it in a query, the second states I am trying to use an
"undefined function in an expression."
I haven't gotten a syntax error so I'm pleased I navigated through the
cryptic maze of writing code. I think its come down to what code god I
haven't worshipped to get this to work. I'm using Access 2000 and Windows
98. Any idea where I'm slipping?
 
Thanks for the quick response. Here is the text I have input in the module.
I'm sure I'm overlooking the obvious. Good Luck! Phil

Option Compare Database

Option Explicit
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
 
The expression I'm using is:
=GetElapsedTime([Dateout] - [Datein])
When I launch the report I get a dialog box that prompts for the
"GetElapsedTime" parameter.
Very confusing. Thanks, Phil
 
I think the naming issue was brought up in Steve Schapel's reply. You could
try the following to get an average.

=GetElapsedTime(Avg([Dateout] - [Datein]))
 
Back
Top