How to display only date as year (yyyy) in txtbox?

S

sebastico

Hello
Access 2003.

I have this code which works well. However, I would like to display only
year (yyyy) in textStart rather than day/month/year. Could you help me how
to do it?

txtStart Default Value : Date()

Private Sub bAddYear_Click()
Select Case Me.fraOptions.Value
Case Is = 1
Me.txtStart.Value = DateAdd("yyyy", 1, [txtStart])
Case Is = 2
Me.txtStart.Value = DateAdd("yyyy", 5, [txtStart])
Case Is = 3
Me.txtStart.Value = DateAdd("yyyy", 10, [txtStart])
End Select

Thanks in advance
 
D

Dirk Goldgar

sebastico said:
Hello
Access 2003.

I have this code which works well. However, I would like to display only
year (yyyy) in textStart rather than day/month/year. Could you help me
how
to do it?

txtStart Default Value : Date()

Private Sub bAddYear_Click()
Select Case Me.fraOptions.Value
Case Is = 1
Me.txtStart.Value = DateAdd("yyyy", 1, [txtStart])
Case Is = 2
Me.txtStart.Value = DateAdd("yyyy", 5, [txtStart])
Case Is = 3
Me.txtStart.Value = DateAdd("yyyy", 10, [txtStart])
End Select

Thanks in advance


If you set the Format property of txtStart to "yyyy" (without the quotes),
the text box will just display the year. Note that the *value* of the text
box will still be a complete date; it's just the way it is displayed that
will be different. And if the user edits the text box, it is the date
value, not just the year, that will be displayed and edited.

If what you really want is just to put a year in the text box, then you need
to set and increment its value differently.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top