none
Adding one week to a date as a Default RRS feed

  • Question

  • I would like to add one week to a date in my Access table for the default setting. I tried using the DateAdd function in the General properties default field for Due Date like this :

    DateAdd("ww",1,[Date Received])

    I was hoping to get a result on my form that would automatically add one week to whatever date value is entered for the Date Received field. The Date Received field is set to a default of today's date.

    Can anyone see what I did wrong or is this not even possible?

    I don't want to have a calculated field, only a default value that can be changed.

    Thank you in advance for your help/suggestions

    Tuesday, July 18, 2017 8:00 PM

All replies

  • Hi Wendy,

    Default Values are calculated for display as soon as a new record needs to be displayed. So, for a new record, if you don't have anything showing in [Date Received], then there is nothing for the Due Date to calculate. Now, if your [Date Received] field has a Default Value of Date(), then you can also use it for the Default Value in [Due Date]. For example, you could try:

    DateAdd("d", 7, Date())

    Hope it helps...

    Tuesday, July 18, 2017 8:18 PM
  • As theDBguy says, you can set the DefaultValue property of the Date Due column to DateAdd("d", 7, Date()) in table design view.  If you then want the  Date Due column to automatically be seven days after the Date Received value in the event of a user changing the value of the latter from the current date, then you should assign a value to it in the AfterUpdate event procedure of the Date Received control in your data entry form with:

    Me.[Date Due] = DateAdd("d", 7, Me.[Date Received])

    The user will then be able to edit the Date Due control to another date if necessary, though note that if they then go back and edit the Date Received control, the Date Due value will again be set to seven days following the Date Received value.

    It goes without saying that data should only be entered or edited via a form, never in a table's raw datasheet view.

    Ken Sheridan, Stafford, England

    Wednesday, July 19, 2017 11:41 PM