Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help, Get Data from Text and the Date Format is not recognized by Acc

Status
Not open for further replies.

DiamondDust

Programmer
Aug 26, 2002
23
0
0
US
I brought in data from a text file with this date format 19770127. I have to bring it in as string because Access does not read this format. Is there a way to change the data type to Date and have Access recognize that format.
 
Hi

assuming txtDate contains 19770127

datDate = CDate(Right(txtDate,2) & "/" & Mid(txtDate,5,2) & "/" & left(txtDate,4))

Should do it if you are confient txtDate always contains a valid date, other wise you might want to is the IsDate() Function to verify the date nefore converting it, eg

If IsDate(Right(txtDate,2) & "/" & Mid(txtDate,5,2) & "/" & left(txtDate,4)) Then
datDate = CDate(Right(txtDate,2) & "/" & Mid(txtDate,5,2) & "/" & left(txtDate,4))
Else
msgbox "Invalid Date"
End If

Ken Reay
Freelance Developer
kenneth.reay@talk21.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top