"oldeast" <oldeast@bigpond.net.auwrote in message
<1180426808.788281.148840@i38g2000prf.googlegroups .com>:
Quote:
Hello all,
I read part of a string (TSFilename) to convert to dates and display
in text box..
It looks fine, but vba doesn't believe they are dates.
Retype the same dates in the textboxes and vba accepts it..
can anyone advise..
>
Thanks.
>
TSFileName is "xx-xxx-2007-05-10to2007--5-20.xls"
Text boxes are formatted to date "dd/mm/yyy"
>
here's a snippet..
varStartDate = Mid(TSFileName, 8, 10)
varEndDate = Mid(TSFileName, 20, 10)
datStartDate = varStartDate
datEndDate = varEndDate
Me![DateStart] = Format(datStartDate, "dd/mm/yyyy")
Me![DateEnd] = Format(datEndDate, "dd/mm/yyyy")
I think that one of the safest methods of retrieving a date out of a
string, is to use DateSerial
Me![DateStart] = DateSerial(Mid$(TSFileName, 8, 4), _
Mid$(TSFileName, 13, 2), Mid$(TSFileName, 16, 2))
Note that when you use the Format function on a date, what you're
doing, is taking a valid date, convert it to a string, and have
Access do an implicit cast back to date by assigning this string to
a control formatted as date. This might give unpredictable results.
--
Roy-Vidar