YEAR Only

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Dan,

Enter the following into the textbox's Format property:
yyyy

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
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.
--
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."
 
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.
 
Back
Top