#error problem with function call.

G

George

Please help. I have a #error problem and can't tell
what's wrong with this call. Can you help?
-----------------------------------------------------------
Option Explicit
Public Function ConvertTime(TimeInput As Text) As String
Dim calTime As Integer

If TimeInput <> " " Then
calTime = Val(TimeInput)
ConvertTime = Format(calTime, "hh:mm:ss AMPM")
'Should return "05:04:23 PM"
Else
Exit Function
End If

End Function
 
W

Wayne Morgan

TimeInput As Text
this should be As String
calTime As Integer
ConvertTime = Format(calTime, "hh:mm:ss AMPM")

The time portion of a number is the decimal portion. With calTime being integer the
decimal portion is zero and this will return 12:00:00 AM every time.

--
Wayne Morgan
Microsoft Access MVP


George said:
Please help. I have a #error problem and can't tell
what's wrong with this call. Can you help?
-----------------------------------------------------------
Option Explicit
Public Function ConvertTime(TimeInput As Text) As String
Dim calTime As Integer

If TimeInput <> " " Then
calTime = Val(TimeInput)
ConvertTime = Format(calTime, "hh:mm:ss AMPM")
'Should return "05:04:23 PM"
Else
Exit Function
End If

End Function
---------------------------------------------------------
The Table field is called TimeInput and is text.
The table is called by a report with the control source
set as....
=ConvertTime([TimeInput])
 
M

Marshall Barton

George said:
Please help. I have a #error problem and can't tell
what's wrong with this call. Can you help?
-----------------------------------------------------------
Option Explicit
Public Function ConvertTime(TimeInput As Text) As String
Dim calTime As Integer

If TimeInput <> " " Then
calTime = Val(TimeInput)
ConvertTime = Format(calTime, "hh:mm:ss AMPM")
'Should return "05:04:23 PM"
Else
Exit Function
End If

End Function
---------------------------------------------------------
The Table field is called TimeInput and is text.
The table is called by a report with the control source
set as....
=ConvertTime([TimeInput])

Shot in the dark - If the text box is named TimeInput,
change it to something else (e.g. txtTimeInput).

OTOH, the function has several suspicious bits. Do you
really place a blank (" ") in the field? Maybe you meant to
use a zero length string ""? Check your field definition in
the table - the field might allow a Null value. A Null in
the field would definitely cause an error since the function
only accepts a string.

I also do not understand how you can convert the string
argument to an integer and then format the integer as a time
value. (An integer will always convert to midnight as a
time.)

Either you are doing something totally unusual or you should
step back and reconsider the whole situation.
 

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