Increase the date by 45 days

B

binder

I have a table that has a date inputed and I would like to have a date in the
following field that is 45 days in the future of the first date. How can I
do this?? This is needed for all of the dates already entered and all of the
dates that will be entered in the future. Thank you!!
 
R

Rick Brandt

binder said:
I have a table that has a date inputed and I would like to have a date in the
following field that is 45 days in the future of the first date. How can I
do this?? This is needed for all of the dates already entered and all of the
dates that will be entered in the future. Thank you!!

Unless you want a date 45 days greater than the other field *as a default*
with the option to change it to something else, then you don't need this
other date in your table at all. Just calculate it in any query, form, or
report where you want to see it using the expression...

DateAdd("d", 45, [OtherDateField])

Basic rule of database design is that no field in a table should have a
value derived from any other fields.
 
T

tobin

For future dates:
On the form, using the date inputed field (AfterUpdate Procedure) use this
code

Private Sub DateInputField_AfterUpdate()
On Error GoTo Errorhandler

If Not IsNull([DateInputField]) Then
[45DayField] = [DateInputField] + 45
Else
[45DayField] = ""
End If

Exit_DateInputField:
Exit Sub

Errorhandler:
MsgBox "Error: " & Err.Number & " - " & Err.Description, vbOKOnly, "Error"

End Sub

For dates that are already existing:
Use an update query with the DateInputField and the 45Day Field. In the
45Day field in the updateto area, enter [DateInputField]+45. When you
execute the query all records will be updated. If you only want records that
don't have a date in that field already, use the is null in the criteria
section.

HTH
 
Top