Autofill future date based on another field

learnaccesscg

Registered User.
Local time
Today, 01:22
Joined
Dec 1, 2014
Messages
12
I am very new to access and I am trying to figure out how to build an expression for one of my fields. I have a field called Order Date, which holds the date of when an order is filled. I then have another field called Fill By Date. This new field I want to be 2 weeks after the Order Date. Is there a way to auto fill this information so that when I enter a date into the Order Date, it will enter the date that is 2 weeks after into the Fill by Date?
 
Your fill-by date is a calculated field and, as a general rule, should NOT be saved as data, but instead calculated on the fly when necessary.

You can do that by setting the control source for your fill-by to blank (nothing showing), and then setting the value in that texbox to two weeks later using DateAdd.
 
I would probably put it in the Lost Focus event of the Order_Date field.

The code would be something like

Me.Fill_By_Date = Me.Order_Date + 14

You might want to protect the Fill_By field, so that it can only get changed if the Order_Date changes?

Not an Access expert, but hope it helps.
 
Thanks Gasman! That worked! How do you protect the Field though?

Much appreciated!
 
Set Enabled = No in the form on the Data tab, or leave it as Yes and set Locked to Yes, or it can be set via VBA with those properties True of False.

If you set it to locked, it can be copied and the pasted somewhere. If disabled then it cannot.

I use Locked in my little database so users can copy the data for other systems.

The choice is yours, Try the options and see the effect.
 

Users who are viewing this thread

Back
Top Bottom