Function not recognized?

G

Guest

I have inserted a function into one of my forms. When I just insert it into
a module by itself it works, but not in my form. It is from the compare 2
times in the Microsoft KB. Does this function need to be in it's own module
in order to work? When I try to call it in my form, it says it doesn't
recognize the sub or function. Thanks!

Option Explicit

Function ElapsedTTime(Interval)
Dim x
x = Int(CSng(Interval * 24 * 3600)) & " Seconds"
Debug.Print x
x = Int(CSng(Interval * 24 * 60)) & ":" & Format(Interval, "ss") _
& " Minutes:Seconds"
Debug.Print x
x = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
& " Hours:Minutes:Seconds"
Debug.Print x
x = Int(CSng(Interval)) & " days " & Format(Interval, "hh") _
& " Hours " & Format(Interval, "nn") & " Minutes " & _
Format(Interval, "ss") & " Seconds"
Debug.Print x

End Function
 
J

Jörg

Hi,

i just created a simple form, only with one button called "Befehl0"

Then i put in the followin code:

---------------------------------------------------------------------
Option Compare Database
Option Explicit

Private Sub Befehl0_Click()
ElapsedTTime (2)
End Sub

Function ElapsedTTime(Interval)
Dim x
x = Int(CSng(Interval * 24 * 3600)) & " Seconds"
MsgBox x
x = Int(CSng(Interval * 24 * 60)) & ":" & Format(Interval, "ss") _
& " Minutes:Seconds"
MsgBox x
x = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
& " Hours:Minutes:Seconds"
MsgBox x
x = Int(CSng(Interval)) & " days " & Format(Interval, "hh") _
& " Hours " & Format(Interval, "nn") & " Minutes " & _
Format(Interval, "ss") & " Seconds"
MsgBox x
End Function
---------------------------------------------------------------------

.... and it works without any problem...

Try it again

Best regards
 
J

Jörg

Hi Roger,

that´s totally right,
but he/she wants to insert it into a form..
so he/she gets his/her answer how to user it in an form ;-)

best regards
 
G

Guest

It has to be in the General section, after any declarations but before any
form object events.
 
G

Guest

The next step for me in order to use this, is to incorporate an interval from
fields off my form. So now I have:

TimeInterval = "#" & LstEndDate & " " & LstEndTime & _
"#-#" & LstBegDate & " " & LstBegTime & "#"

This is equivalent to: #11/3/2005 3:00:00 PM#-#11/1/2005 2:00:00 PM#

But now the function doesn't work? Is it because the interval is now a
string? Do I need to convert it before using the function
ElapsedTime(TimeInterval)? Any ideas?
 
J

Jörg

Hi,

try this:

MsgBox DateDiff("h", #11/1/2005 2:00:00 PM#, #11/3/2005 3:00:00 PM#)

Best regards
 

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