Connecting Tech Pros Worldwide Help | Site Map

Get Dates from string Acc 2003

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 29th, 2007, 08:25 AM
oldeast
Guest
 
Posts: n/a
Default Get Dates from string Acc 2003

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, 09:05 AM
RoyVidar
Guest
 
Posts: n/a
Default 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, 04:35 AM
oldeast
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.