By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,767 Members | 1,026 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,767 IT Pros & Developers. It's quick & easy.

Get Dates from string Acc 2003

P: 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")

May 29 '07 #1
Share this Question
Share on Google+
2 Replies

P: n/a
"oldeast" <ol*****@bigpond.net.auwrote in message
<11**********************@i38g2000prf.googlegroups .com>:
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
May 29 '07 #2

P: n/a
On May 29, 4:44 pm, RoyVidar <roy_vidarNOS...@yahoo.nowrote:
"oldeast" <olde...@bigpond.net.auwrote in message

<1180426808.788281.148...@i38g2000prf.googlegroups .com>:


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- Hide quoted text -

- Show quoted text -
Thanks for the reply.
I should have verified the text boxes with IsDate function as well.

May 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.