I want to set a calculated field in my access to get difference between 2 dates. How should I set it up so that as I fill in the form the field gets filled automatically.
I want to set a calculated field in my access to get difference between 2 dates. How should I set it up so that as I fill in the form the field gets filled automatically.
Take a look at the DateDiff() function: http://www.techonthenet.com/access/f...e/datediff.php
If this helped, please click the star at the bottom left of this posting and add to my reputation. Many thanks.
Bob Fitzpatrick
Since this is a calculated value, it doesn't need to be (and shouldn't be) stored in the underlying Table; you just re-calculate it, as needed. This means you can use the Control Source of the Textbox that will hold the difference. So, in the Control Source Property you enter something like:
=DateDiff("d",[Datefield1], [DateField2])
In this example, the number of days is being calculated, hence the "d" in the Interval Parameter. For Intervals other than days, look at the site Bob directed you to.
Also note that in the Control Source you have to surround Control Names with Square Brackets, as shown above.
Alternatively, if your Form is based on a Query, you could do the same thing in the Query. In Query Design, in a blank field, enter something like this:
DateDifference: DateDiff("d",[Datefield1], [DateField2])
Now, on your Form, select the Field DateDifference as the Control Source for the Textbox.
Linq ;0)>