update date field from another field

Mi

Board Regular
Joined
Sep 19, 2004
Messages
77
Help
I have a RecDate field on form. I would like another field, DueDate to be 15 days after the RecDate field.
Considerations: Need to be able to manually override the DueDate field if needed. Would like to the have the DueDate to always be a Monday, but that is more of a wish.

I looked at DateAdd but nothing I have tried seems to work. Not sure where to put it.

Mi
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi Mi
If you go into the form design, right click the [RecDate] field -> Properties -> Event Tab -> After Update -> Click the ... button to activate the Builder -> Code Builder -> Ok -> enter this (without the two outermost quotes) "[DueDate] = DateAdd("d",15,[RecDate])" -> Save and close the VB window -> Save the form.

The code should look like this (before you close the VB window):
Private Sub RecDate_AfterUpdate()
[DueDate] = DateAdd("d", 15, [RecDate])
End Sub

This will update the 'DueDate' field to 15 days after the 'RecDate'.

If you want to force it to be a Monday (the following Monday, if not already a Monday), then use this code instead :
[DueDate] = DateAdd("d", IIf(Weekday(DateAdd("d", 15, [RecDate])) < 3, 2 - Weekday(DateAdd("d", 15, [RecDate])), 9 - Weekday(DateAdd("d", 15, [RecDate]))), DateAdd("d", 15, [RecDate]))
HTH, Andrew. :)
 
Upvote 0
Thanks! Works like a dream. I was trying to put the code in the DueDate field rather that than the RecDate. The Monday thing was a big BONUS.

Your an Angel!

Mi
 
Upvote 0

Forum statistics

Threads
1,221,875
Messages
6,162,563
Members
451,775
Latest member
Aiden Jenner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top