Make two date fields on a form automatically show values

SteveL13
SteveL13 used Ask the Experts™
on
This is similar to another post from a couple of weeks ago.  Two issues:  If a date field on a form is 11/19/2020...

1) How can I make a 2nd date field on the form show 11/19/2021.

and

2)  How can I make a 3rd date field on the form show 1/19/2022.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
ControlSource of the second date control:

=DateAdd("yyyy", 1, [FirstDateField])

Open in new window

and the third date control:

=DateAdd("yyyy", 2, [FirstDateField])

Open in new window

Author

Commented:
Perfect.  Again, thank you.
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
You are welcome!
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Not sure when you want to do this, if those other two date fields are bound to fields in your database, then the best time to do this would be in the AfterUpdate event of the first date field.  But realistically, you should not even store those values since they can be easily computed either by setting the control source of the textbox

= DateAdd("yyyy", 1, [DateField])

or by creating a query that provides those values

SELECT *, DateAdd("yyyy", 1, [DateField]) as Date2, DateAdd("yyyy", 2, [DateField]) as Date3
FROM yourTable

but if you insist on adding these columns to your database, you could also set them up as computed columns so that any time that the [datefield] is updated, those columns also get updated.

Author

Commented:
I'm storing the dates via the oncurrent event of the form.  Is that a good way to do it?
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Like I said, in a perfect world, you would not store those values at all, you would use a query to generate them based on the first date field.
As much as I dislike computed fields, that is the way I would handle these in your database.  That way, no matter how or when someone changes the [Date1] value, these values would automatically change to the appropriate new value.  If you just define these as date fields in your table, then anyone who is able to open the backend or the tables in the FE, could change the [Date1] value and these values would not change.

Dale
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
As I assumed, use the expressions as ControlSource of the two date controls on the form, not in the table.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial