We help IT Professionals succeed at work.

Date field2 calculate 30 days after the date of date field1

Blacksh
Blacksh asked
on
Hello. I am using Microsoft Access 2000. I have two date fields in a form. Datefield1 is any date (usually today's date). I would like date field2 to calculate 30 days from date field1. I am using a form that is connected to a table.
Comment
Watch Question

Top Expert 2016
Commented:

  you can use DateAdd()fucntion

place this code in the current event of the form or in the afterupdate event of field1

me.field2=dateadd("d",30,Me.field1)
Top Expert 2009
Commented:
It is better to place the DateAdd expression in the control source of an unbound textbox.  The expression will not be written to the table field, but it should not be, since it could become inaccurate if the first date was changed.  You can also use the DateAdd expression in a query, used as the form's record source.  That way it will always be accurate.
Most Valuable Expert 2015
Distinguished Expert 2018

Commented:
Use the ControlSource of the TextBox for field2 to obtain an automatic update whenever field1 changes. If "from field1" means "before field1" then:

=DateAdd("d",-30,[txtNameOfTextBoxOfField1])

However, at months' end - ultimo - you will probably obtain a better result by subtracting a month:


=DateAdd("m",-1,[txtNameOfTextBoxOfField1])

Further, field1 may be empty (Null), thus:

=IIf(IsNull([txtNameOfTextBoxOfField1]),Null,DateAdd("d",-30,[txtNameOfTextBoxOfField1]))

Of course, if "from field1" means "after field1" then remove the minus sign.
/gustav

Author

Commented:
Thank you very much.