Connecting Tech Pros Worldwide Help | Site Map

Get Dates from string Acc 2003

  #1  
Old May 29th, 2007, 09:25 AM
oldeast
Guest
 
Posts: n/a
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")

  #2  
Old May 29th, 2007, 10:05 AM
RoyVidar
Guest
 
Posts: n/a

re: Get Dates from string Acc 2003


"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


  #3  
Old May 30th, 2007, 05:35 AM
oldeast
Guest
 
Posts: n/a

re: Get Dates from string Acc 2003


On May 29, 4:44 pm, RoyVidar <roy_vidarNOS...@yahoo.nowrote:
Quote:
"oldeast" <olde...@bigpond.net.auwrote in message
>
<1180426808.788281.148...@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..
>
Quote:
Thanks.
>
Quote:
TSFileName is "xx-xxx-2007-05-10to2007--5-20.xls"
Text boxes are formatted to date "dd/mm/yyy"
>
Quote:
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- Hide quoted text -
>
- Show quoted text -
Thanks for the reply.
I should have verified the text boxes with IsDate function as well.

Closed Thread