I would like to return only the YEAR in a Text Box on a form.
I tried adding this to the Text Box but it still returns the mm/dd/yyyy
Private Sub TR_CLOSEDATE_BeforeUpdate(Cancel As Integer)
Dim LYear As Integer
LYear = Year(TR_CLOSEDATE)
End Sub
Suggestions
Graham R Seach - 23 May 2007 14:11 GMT
Dan,
Enter the following into the textbox's Format property:
yyyy
Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
>I would like to return only the YEAR in a Text Box on a form.
> I tried adding this to the Text Box but it still returns the mm/dd/yyyy
[quoted text clipped - 6 lines]
>
> Suggestions
Al Campagna - 23 May 2007 14:27 GMT
Dan,
Well, you'll need to rethink this setup a bit....
Since you capture TR_CLOSEDATE, there's no need to "capture" the Year of that date.
Don't store a value in a table that can be derived/caculated at any time "on the fly"
from values you already have.
Given an ubound text control on the form called LYear (formatted for whole numbers (#)
with no decimals) this ControlSource will always "display" the correct Year...
= Year(TR_CLOSEDATE)
You would use the same method in any subsequent form, query, or report to "regenerate"
the Year, when you need it.

Signature
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."
>I would like to return only the YEAR in a Text Box on a form.
> I tried adding this to the Text Box but it still returns the mm/dd/yyyy
[quoted text clipped - 6 lines]
>
> Suggestions
missinglinq - 23 May 2007 14:37 GMT
How are you placing the value in the textbox? The code you posted only
assigns the year to a variable, LYear, not a textbox. Assuming TR_CloseDate
is a valid date, Year(TR_CloseDate) should yield the year.

Signature
There's ALWAYS more than one way to skin a cat!
Answers/posts based on Access 2000