Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Dates Automatically

Status
Not open for further replies.

jbento

Technical User
Jul 20, 2001
573
US
All,
I have a text field called "iecd_year". For now it has a default value of: c03.

The 3 on the end represents the current year. I would like to have that automatically change every year. Therefore, when year 2004 comes, I would like the default value to automatically change to: c04 and so on every year after.

Does anyone know how to make this happen?

I would really appreciate the help.

Thanks,

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Use the following

="c" & Right(CStr(DatePart("yyyy",Date())),2)

Hope this helps.

Regards
Warwick
 
Wow,
I just tried it and it worked like a charm.

Thank you so VERY much!!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Wocca,
I have Access 2002 at home and this code works great: ="c" & Right(CStr(DatePart("yyyy",Date())),2), but I have Access 2000 at work and it does not work.

Do you know how to make this work on Access 2000?

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
If you change your text field to a date field and in the table design view put "c"yy in the format property and Date() in the default value property you will be all set.

Good Luck

Shane
 
Works on Ms.A. 2K. To get a return for an arbitrary date, Replace Date() with a date type variable (e.g. MyDate) without the parnes.

e.g. {code]
? "c" & Right(CStr(DatePart("yyyy",Date)),2)
c03


MyDate = #6/6/04#
? "c" & Right(CStr(DatePart("yyyy",MyDate)),2)
c04
[/code]

Note: the parens following "Date" are not required in the original form either.



MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
I am going to try those suggestions on Monday at work, and I will let you all know how it turns out, since the version at work MS Access 2000.

You all have a wonderful weekend!!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
All,
I tried Swaybright's way and it worked like a charm. I also tried MichaelRed's way, but it still wouldn't format. Once I put "c" & Right(CStr(DatePart("yyyy",MyDate)),2) in the format field, it still didn't work.

Maybe I'm missing something here. Maybe there is something else I need to do to make that one work, but for now I have Swaybright's suggestion working.

I REALLY APPRECIATE EVERYONE HELPING WITH THIS THING!!!!

Jerome Benton
JERPAT Web Designs
GOD Is Good All The Time!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top