I'm processing an Excel workbook with Access VBA (see Reading an Excel workbook from Access) and now I want to check if a cell contains a valid time value. For dates I use IsDate() and it works fine.
But with time values it doesn't (since there is no IsTime() I also use IsDate() for time values). Or should I use IsNumeric because time values are stored as doubles?
With " 12:00:00" (with space) IsDate() gives TRUE (!?) but Excel itself doesn't recognize it as a time value, the VBA debugger also shows it as a text string.
With "12:00:00" IsDate() gives FALSE but Excel itself recognize it as a time value, the VBA debugger shows the value 0,5.
Anybody?
UPDATE 9/12:
Thanks to @belisarius and @mwolfe02 I found this for my situation:
/* Valid time value */
IsDate() = False,
IsNumeric() = True,
TypeName() = Double
/* Numeric (no time) value */
IsDate() = False,
IsNumeric() = True,
TypeName() = Double
/* Valid date value */
IsDate() = True,
IsNumeric() = False,
TypeName() = Date
/* Invalid time value (e.g. with leading space as in above example) */
IsDate() = True,
IsNumeric() = False,
TypeName() = String
So I only need to check if TypeName()
returns Double
and IsNumeric() True
and to avoid confusion with 'normal' numeric values if the value is >= 0 and < 1. Right?