Subtract 1 year from date in form

L

Linda Brown

I have a form with a column where I need to type a date (inside Access
2002-2003). As you know, once I enter the month and day and immediately tab
off the filed, the date adds the current year. To make things simpler each
year when we enter data in the form and the data date is for December, how
can I make the field to change to the previous year? For instance, I want
the field to automatically enter 12-17-2007 (without entering 2007). If I
enter 12-17 and tab off, the system automatically puts in 2008. Is there
some code to use (perhaps dealing with DateDiff) that deducts 1 year using an
If clause that takes into account the month being 12. (I can comment out the
code until the following year arrives and start the process over.)

Thank you for any assistance.
 
J

John W. Vinson

I have a form with a column where I need to type a date (inside Access
2002-2003). As you know, once I enter the month and day and immediately tab
off the filed, the date adds the current year. To make things simpler each
year when we enter data in the form and the data date is for December, how
can I make the field to change to the previous year? For instance, I want
the field to automatically enter 12-17-2007 (without entering 2007). If I
enter 12-17 and tab off, the system automatically puts in 2008. Is there
some code to use (perhaps dealing with DateDiff) that deducts 1 year using an
If clause that takes into account the month being 12. (I can comment out the
code until the following year arrives and start the process over.)

Thank you for any assistance.

I'd be rather uncomfortable with this... having the computer "helpfully"
change what the user types to something else is risky, because the user might
have INTENDED a 2008 date, or they might get used to the anomalous behavior.

But yes... you can do this in the textbox's AfterUpdate event:

Private Sub textboxname_AfterUpdate()
' Put in previous year if user enters a December date during January
If Month(Me!textboxname) = 12 And Month(Date) = 1 Then
Me!textboxname = DateAdd("yyyy", -1, Me!textboxname)
End If
End Sub

John W. Vinson [MVP]
 

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