How to check Excel time values in Access VBA? -


i'm processing excel workbook access vba (see reading excel workbook access) , want check if cell contains valid time value. dates use isdate() , works fine.

but time values doesn't (since there no istime() use isdate() time values). or should use isnumeric because time values stored doubles?

with " 12:00:00" (with space) isdate() gives true (!?) excel doesn't recognize time value, vba debugger shows text string.

with "12:00:00" isdate() gives false excel recognize time value, vba debugger shows value 0,5.

anybody?

update 9/12:

thanks @belisarius , @mwolfe02 found 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. leading space in above example) */ isdate() = true, isnumeric() = false, typename() = string 

so need check if typename() returns double , isnumeric() true , avoid confusion 'normal' numeric values if value >= 0 , < 1. right?

there 2 different concepts:

1) date & time format

when format cell in excel contain date (and/or) time, excel uses internal representation. according ms:
by default, january 1, 1900 serial number 1, , january 1, 2008 serial number 39448 because 39,448 days after january 1, 1900. microsoft excel macintosh uses different date system default. numbers right of decimal point in serial number represent time; numbers left represent date. example, serial number .5 represents time 12:00 noon.

and it. dates , times stored decimal numbers.

2) things vba could convert date/time

this isdate checks. according ms:

returns boolean value indicating whether expression can converted date.
true returned isdate not mean cell has been formatted date/time, tells you may convert value date/time. worse: function may return different values different platforms: in microsoft windows, range of valid dates january 1, 100 a.d. through december 31, 9999 a.d.; ranges vary among operating systems.

what clear excel did not validate contents of cell date/time. it's sure text containing whatever characters user typed in (as space in example). isdate() return telling vba not able convert value date, perhaps can, if know format (and write ad-hoc function conversion).

hth!

edit think answer this question may too.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -