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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text To Date Format

Status
Not open for further replies.

Survane

MIS
Jul 3, 2002
74
US
This is my code:
Private Sub txtTestDate_AfterUpdate()
Dim str_txtTestDate As Date
str_txtTestDate = Me!txtTestDate.value
Me!txtTestYear = Year(str_txtTestDate)
Me!txtModifiedTestDatebyMonth = Month(str_txtTestDate)
Me!txtTestDate1 = Me!txtTestDate
End Sub


I have a "non date" type field and I am trying to format it to a date after updating it. It is being selected from a calendar control which works well but it is not working. What am I doing wrong?
Thanks.
 
You might try converting the string to a Date with CDate() at the beginning of your procedure. I don't think that the Year and Month functions will work properly unless the parameter can be evaluated as a date. Try replacing your assignment with this. Don't know if it will work, but it's worth a try.

str_txtTestDate = CDate(Me!txtTestDate.value)
dz
dzaccess@yahoo.com
 
I just tried this and it didn't work. I'll try your way.

Private Sub txtTestDate_AfterUpdate()
Dim str_txtTestDate As String
Dim str_txtTestDate1 As String

str_txtTestDate = Me!txtTestDate.value
str_txtTestDate1 = CDate(str_txtTestDate)


Me!txtTestYear = Year(str_txtTestDate1)
Me!txtModifiedTestDatebyMonth = Month(str_txtTestDate1)

Me!txtTestDate1 = str_txtTestDate1
End Sub
 
By the way, I just noticed that you are using Me! Did you mean to use Me.? If that isn't causing this problem, it would cause another problem....unless I misinterpreted your code?

Best, dz
dzaccess@yahoo.com
 
Can you provide a couple of examples of the data in the field named "str_txtTestDate".

Thanks, dz
dzaccess@yahoo.com
 
Correct a typo:

Can you please provide a couple of examples of the data in the field named "txtTestDate". The data has to be in a format that can evaluate to a date. dz
dzaccess@yahoo.com
 
the data in field txtTestDate are short dates converted into the format MMM-YY after update or change.

Basic format 7/22/02 - JUL-02

 
Hi Survane,

Maybe I didn't ask the right question. In the first post of this thread, you said "I have a "non date" type field and I am trying to format it to a date after updating it." Is that not txtTestDate? The format that you provided in the last post is a date format. So now I'm confused.

Best dz
dzaccess@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top