Results 1 to 3 of 3
  1. #1
    Sujathajosh is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2014
    Posts
    1

    Access formula


    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.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    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

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    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)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Writing a Formula in Access
    By efmbman in forum Access
    Replies: 11
    Last Post: 07-09-2013, 10:47 AM
  2. Help with Access Formula
    By tdawn in forum Access
    Replies: 5
    Last Post: 03-24-2013, 11:43 AM
  3. Average formula on access
    By chivo123 in forum Access
    Replies: 2
    Last Post: 01-28-2012, 11:31 AM
  4. access query formula
    By simpleman in forum Queries
    Replies: 6
    Last Post: 11-26-2009, 09:13 AM
  5. Max formula in Access
    By mohsin74 in forum Programming
    Replies: 2
    Last Post: 12-26-2006, 07:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums