PC Review


Reply
Thread Tools Rate Thread

How to display only year as date in txtbox

 
 
sebastico
Guest
Posts: n/a
 
      17th May 2010
Hello
Access 2003
txtAddYear
Default Value: Date()

In a form I have this code which works well. However, I need to display only
year in txtbox. Could you help me how to do it?

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
End Sub
 
Reply With Quote
 
 
 
 
John W. Vinson
Guest
Posts: n/a
 
      17th May 2010
On Mon, 17 May 2010 09:14:01 -0700, sebastico
<(E-Mail Removed)> wrote:

>Hello
>Access 2003
>txtAddYear
>Default Value: Date()
>
>In a form I have this code which works well. However, I need to display only
>year in txtbox. Could you help me how to do it?


Simply use the field as the Control Source for the textbox and set its Format
property to "yyyy".

The field will still contain the complete date, but all you will see will be
the year portion. If you select into the field to edit it you'll see the
entire date.
--

John W. Vinson [MVP]
 
Reply With Quote
 
sebastico
Guest
Posts: n/a
 
      18th May 2010

John
If I understood, I wrote "yyyy" in the format's field. However, the txtStar
still displays the entire date dd/m/yyyy.
On the other hand, could you tell me how to display year 1960 in txtStart
any time the forms is open?

Many thanks for your kindness
"John W. Vinson" wrote:

> On Mon, 17 May 2010 09:14:01 -0700, sebastico
> <(E-Mail Removed)> wrote:
>
> >Hello
> >Access 2003
> >txtAddYear
> >Default Value: Date()
> >
> >In a form I have this code which works well. However, I need to display only
> >year in txtbox. Could you help me how to do it?

>
> Simply use the field as the Control Source for the textbox and set its Format
> property to "yyyy".
>
> The field will still contain the complete date, but all you will see will be
> the year portion. If you select into the field to edit it you'll see the
> entire date.
> --
>
> John W. Vinson [MVP]
> .
>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      18th May 2010
If you want only the year in the text box why not use the Year function to
place that in the text box.

Default Value: Year(Date())

Adding to the year would be simple
Private Sub bAddYear_Click()
Select Case Me.fraOptions.Value
Case Is = 1
Me.txtStart.Value = me.TxtStart + 1
Case Is = 2
Me.txtStart.Value = me.TxtStart + 5
Case Is = 3
Me.txtStart.Value = me.TxtStart + 10
End Select
End Sub

If you always want 1960 as the start point then enter that value as the
default value.

The best solution depends on what you want to do with the value in the text
box. If you need to use the year value to generate a date (or date range)
then you may be able to use the DateSerial function to generate a date based
on the value of txtStart.

For instance
DateSerial(txtStart,1,1)
would give you January 1 of the relevant year.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County


sebastico wrote:
> John
> If I understood, I wrote "yyyy" in the format's field. However, the txtStar
> still displays the entire date dd/m/yyyy.
> On the other hand, could you tell me how to display year 1960 in txtStart
> any time the forms is open?
>
> Many thanks for your kindness
> "John W. Vinson" wrote:
>
>> On Mon, 17 May 2010 09:14:01 -0700, sebastico
>> <(E-Mail Removed)> wrote:
>>
>>> Hello
>>> Access 2003
>>> txtAddYear
>>> Default Value: Date()
>>>
>>> In a form I have this code which works well. However, I need to display only
>>> year in txtbox. Could you help me how to do it?

>> Simply use the field as the Control Source for the textbox and set its Format
>> property to "yyyy".
>>
>> The field will still contain the complete date, but all you will see will be
>> the year portion. If you select into the field to edit it you'll see the
>> entire date.
>> --
>>
>> John W. Vinson [MVP]
>> .
>>

 
Reply With Quote
 
sebastico
Guest
Posts: n/a
 
      18th May 2010

Well
The txtStart has by Default Value Date(). If I write "yyyy" when I open the
form txtStar displays same dd/m/yyyy.

don't know what you mean by "the format's field", but the suggestion was to
> set the format property of the *text box* to "yyyy".


I did it, but txtStart shows the date as dd/m/yyyy.

"BruceM via AccessMonster.com" wrote:

> I don't know what you mean by "the format's field", but the suggestion was to
> set the format property of the *text box* to "yyyy".
>
> It is very unclear what you are trying to do. Is txtStart bound to a field?
> It seems you want to change the value in txtStart based on fraOptions, but
> only if the user clicks a command button (or whatever bAddYear is). If
> txtStart is unbound, the value will remain for every record until you click
> the command button again. Why not store the original date, and calculate the
> DateAdd date?
>
>
> sebastico wrote:
> >John
> >If I understood, I wrote "yyyy" in the format's field. However, the txtStar
> >still displays the entire date dd/m/yyyy.
> >On the other hand, could you tell me how to display year 1960 in txtStart
> >any time the forms is open?
> >
> >Many thanks for your kindness
> >
> >> >Hello
> >> >Access 2003

> >[quoted text clipped - 10 lines]
> >> the year portion. If you select into the field to edit it you'll see the
> >> entire date.

>
> --
> Message posted via AccessMonster.com
> http://www.accessmonster.com/Uwe/For...dules/201005/1
>
> .
>

 
Reply With Quote
 
sebastico
Guest
Posts: n/a
 
      18th May 2010

John
txtStart now shows only the year as I need. However, txt shows 2010 and I
need 1960 as start year. T
I'm sorry that I don't understand your last lines
"John Spencer" wrote:

> If you want only the year in the text box why not use the Year function to
> place that in the text box.
>
> Default Value: Year(Date())
>
> Adding to the year would be simple
> Private Sub bAddYear_Click()
> Select Case Me.fraOptions.Value
> Case Is = 1
> Me.txtStart.Value = me.TxtStart + 1
> Case Is = 2
> Me.txtStart.Value = me.TxtStart + 5
> Case Is = 3
> Me.txtStart.Value = me.TxtStart + 10
> End Select
> End Sub
>
> If you always want 1960 as the start point then enter that value as the
> default value.
>
> The best solution depends on what you want to do with the value in the text
> box. If you need to use the year value to generate a date (or date range)
> then you may be able to use the DateSerial function to generate a date based
> on the value of txtStart.
>
> For instance
> DateSerial(txtStart,1,1)
> would give you January 1 of the relevant year.
>
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
>
>
> sebastico wrote:
> > John
> > If I understood, I wrote "yyyy" in the format's field. However, the txtStar
> > still displays the entire date dd/m/yyyy.
> > On the other hand, could you tell me how to display year 1960 in txtStart
> > any time the forms is open?
> >
> > Many thanks for your kindness
> > "John W. Vinson" wrote:
> >
> >> On Mon, 17 May 2010 09:14:01 -0700, sebastico
> >> <(E-Mail Removed)> wrote:
> >>
> >>> Hello
> >>> Access 2003
> >>> txtAddYear
> >>> Default Value: Date()
> >>>
> >>> In a form I have this code which works well. However, I need to display only
> >>> year in txtbox. Could you help me how to do it?
> >> Simply use the field as the Control Source for the textbox and set its Format
> >> property to "yyyy".
> >>
> >> The field will still contain the complete date, but all you will see will be
> >> the year portion. If you select into the field to edit it you'll see the
> >> entire date.
> >> --
> >>
> >> John W. Vinson [MVP]
> >> .
> >>

> .
>

 
Reply With Quote
 
John Spencer
Guest
Posts: n/a
 
      18th May 2010
IF you want the value to default to 1960. THEN enter 1960 as the default value
for the control.

I don't know what else or how else to tell you that.

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

sebastico wrote:
> John
> txtStart now shows only the year as I need. However, txt shows 2010 and I
> need 1960 as start year. T
> I'm sorry that I don't understand your last lines
> "John Spencer" wrote:
>
>> If you want only the year in the text box why not use the Year function to
>> place that in the text box.
>>
>> Default Value: Year(Date())
>>
>> Adding to the year would be simple
>> Private Sub bAddYear_Click()
>> Select Case Me.fraOptions.Value
>> Case Is = 1
>> Me.txtStart.Value = me.TxtStart + 1
>> Case Is = 2
>> Me.txtStart.Value = me.TxtStart + 5
>> Case Is = 3
>> Me.txtStart.Value = me.TxtStart + 10
>> End Select
>> End Sub
>>
>> If you always want 1960 as the start point then enter that value as the
>> default value.
>>
>> The best solution depends on what you want to do with the value in the text
>> box. If you need to use the year value to generate a date (or date range)
>> then you may be able to use the DateSerial function to generate a date based
>> on the value of txtStart.
>>
>> For instance
>> DateSerial(txtStart,1,1)
>> would give you January 1 of the relevant year.
>>
>> John Spencer
>> Access MVP 2002-2005, 2007-2010
>> The Hilltop Institute
>> University of Maryland Baltimore County
>>
>>
>> sebastico wrote:
>>> John
>>> If I understood, I wrote "yyyy" in the format's field. However, the txtStar
>>> still displays the entire date dd/m/yyyy.
>>> On the other hand, could you tell me how to display year 1960 in txtStart
>>> any time the forms is open?
>>>
>>> Many thanks for your kindness
>>> "John W. Vinson" wrote:
>>>
>>>> On Mon, 17 May 2010 09:14:01 -0700, sebastico
>>>> <(E-Mail Removed)> wrote:
>>>>
>>>>> Hello
>>>>> Access 2003
>>>>> txtAddYear
>>>>> Default Value: Date()
>>>>>
>>>>> In a form I have this code which works well. However, I need to display only
>>>>> year in txtbox. Could you help me how to do it?
>>>> Simply use the field as the Control Source for the textbox and set its Format
>>>> property to "yyyy".
>>>>
>>>> The field will still contain the complete date, but all you will see will be
>>>> the year portion. If you select into the field to edit it you'll see the
>>>> entire date.
>>>> --
>>>>
>>>> John W. Vinson [MVP]
>>>> .
>>>>

>> .
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display only date as year (yyyy) in txtbox? sebastico Microsoft Access VBA Modules 1 18th May 2010 12:34 AM
Get dates from table where month and year like txtbox Gator Microsoft Access Form Coding 5 14th Nov 2008 10:35 PM
CAn the calendar display the day of the year with the date =?Utf-8?B?TGl6ZXR0ZSBLb2VobGVy?= Microsoft Outlook Calendar 1 27th Aug 2006 08:20 PM
How do I get a date value to display just the month and year?( i.. =?Utf-8?B?QWNjZXNzIE5vdmljZQ==?= Microsoft Access Form Coding 3 8th Dec 2004 08:04 PM
Re: date display on a New Year Norman Harker Microsoft Excel Worksheet Functions 0 22nd Jul 2003 02:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.