View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default iserror(Timevalue())

On e way or another, you have to go down the error handling rout, but you
can mitigate by using a global function, like so

Function IsOK(txt As String)
Dim mTime

On Error Resume Next
mTime = TimeValue(txt)
On Error GoTo 0
If IsEmpty(mTime) Then
If UCase(txt) = "TBA" Then
IsOK = UCase(txt)
Else
IsOK = ""
End If
Else
IsOK = mTime
End If

End Function


and call in your textbox code with

If IsOK(TextBox1.Text) < "" Then
MsgBox "OK"
Else
MsgBox "Not OK"
End If



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Basil" wrote in message
...
Hiya,

I have a form with a textbox in it.
I want the user to either enter 'TBA' or a valid time.

I have put the following code together but need to make an amendment to

get
it work:

If UCase(txttime) = "TBA" Or Not IsError(TimeValue(txttime)) Then
txttime = UCase(txttime)
Else
lblerrtime.Visible = True
End If

An error and halt in code only arises if the textbox contains something

that
cannot be converted to a time.
Could it be because "The IsError function is used to determine if a

NUMERIC
expression represents an error" - as it says in helpfile?

Any ideas what I can do? I'd rather not go down the VBA error handling

route
as there are loads of textboxes I have to deal with (each resulting in
different outcomes).

Many thanks for any thought,

Basil