formatting textbox as to show year, yyyy

H

Haroon

hi

i have a textbox and date picker, when i select date on the calender, it
shows up on the textbox as 13/01/2009, however, i want to show only the year
in the textbox, e.g. 2009, i have assigned code to the textbox but it shows
2009 as 1905.

my textbox code is

Private Sub TextBox2_Change()
TextBox2.Text = Format(TextBox2.Text, "YYYY")

anyone knows what seems to be the problem and why it shows 2009 as 1905 in
the textbox?

cheers.
 
J

Jay Freedman

Haroon said:
hi

i have a textbox and date picker, when i select date on the calender,
it shows up on the textbox as 13/01/2009, however, i want to show
only the year in the textbox, e.g. 2009, i have assigned code to the
textbox but it shows 2009 as 1905.

my textbox code is

Private Sub TextBox2_Change()
TextBox2.Text = Format(TextBox2.Text, "YYYY")

anyone knows what seems to be the problem and why it shows 2009 as
1905 in the textbox?

cheers.

Why are you trying to modify the value _after_ it's transferred from the
date picker to the textbox? That's a good way to get into an infinite loop,
as the Change procedure gets called because it changed the box's value.

Instead, fill the textbox by formatting the .Value of the date picker in the
date picker's Change procedure:

Private Sub DTPicker1_Change()
TextBox2.Text = Format(DTPicker1.Value, "YYYY")
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
H

Haroon

thanks Jay your a star *



Jay Freedman said:
Why are you trying to modify the value _after_ it's transferred from the
date picker to the textbox? That's a good way to get into an infinite loop,
as the Change procedure gets called because it changed the box's value.

Instead, fill the textbox by formatting the .Value of the date picker in the
date picker's Change procedure:

Private Sub DTPicker1_Change()
TextBox2.Text = Format(DTPicker1.Value, "YYYY")
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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