> Is there an easy way to validate with VBA that a user entered a time value
into a text box? I didn't see anything in the validation options on the text
box properties.
Steve
The function below will validate whether they've entered a time value.
Note that it doesn't accept date/time values that include the date
part. So check out the results:
---
?istime(null)
False
?istime("test")
False
?istime("5/5")False
False
?istime("2/2 12 p")
False
?istime("12 p")
True
---
'---
Public Function IsTime(dat As Variant) As Boolean
'handle null values
If IsNull(dat) Then
IsTime = False
'handle text-values, or values that would otherwise not convert to
a date
ElseIf Not IsDate(dat) Then
IsTime = False
'handle valid 'date' values, but ensure the date part of the
date/time value
'has not been entered. We only want the 'time' part of the
date/time value.
ElseIf Fix(CDbl(CDate(dat))) <> 0# Then
IsTime = False
'ok, so it's a valid date, and it is between 0 and 24 hours, i.e.
it's a time value.
Else
IsTime = True
End If
End Function
'---
Enjoy,
Pete