Results 1 to 6 of 6
  1. #1
    tdawn is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3

    Help with Access Formula

    Hey guys, I need help creating a formula. I'm really new to this and can use all the help I can get.



    I am trying to create a formula and I will do my best to describe what I need.

    If [date of hire] is < or = to 1 year from today's date
    then populate [new hire] with a zero.

    If [date of hire] is > 1 year from today's date and [years since last evaluation] is null (empty)
    then populate [years since last evaluation] with difference of today's date [date of hire]

    I also need the [years since last evaluation] to be in decimal format. Like if it's a year and 3 months then I need it to say 1.4.

    I really appreciate any help you guys can give me!! Thank you all in advance!!

    Also, does anyone happen to know a good source of info when I can start learning how to create basic formulas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Requires VBA code to save the calculated value.

    Ideally, don't populate fields with calculated results, just do calcs when needed. A basic principle of relational database is save raw data, do calcs on reports. Problem with storing calculated results is the calc can get 'out-of-sync' with the raw data. If there is an error updating the calculated value, fixing the result can be difficult, especially with cumulative data like in financial accounting. Your data is not cumulative so maybe not so critical but still requires code to save calc result.

    To just calc 'on the fly' in query or in textbox ControlSource on form or report:

    IIf([date of hire]<= DateAdd("y",1,Date()),0,-1)

    Do you not have a separate table that stores the evaluation data, including date of evaluation?

    Google: Access expressions
    http://office.microsoft.com/en-us/ac...010096295.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    tdawn is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3
    Thank you so much for your help. I hope in my response I do not sound like a complete beginner ( I am). The table that I am working with has quite a few fields. I don't have it in front of me but I do know there is field for [date of hire] , [years since last evaluation], [new hire]. If the date of hire is less than 1 year from todays date then it should put a zero in the [new hire field]. If they have not had an eval and they are not new then the difference should be put in the [years since last evaluation] field.

    I really appreciate your advice about not populating fields with calcs but with this one I'll do it in the access table.

    The formula you provided did not mention anything about putting the answer of the calculation in the [years since last evaluation] field. Do you have anything insight on this??

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    I did mention requires VBA code to save calculated value.

    With a form open to the record, code in some event can save the results to fields. The real trick is figuring out what event to put code in.

    Me![years since last evaluation] = Me.textboxname

    However, the calcs you need can be done on-the-fly whenever needed.

    Calcs in query:

    SELECT *, IIf([date of hire]<= DateAdd("y",1,Date()),0,-1) AS IsNewHire, IIf([IsNewHire], Null, DateDiff("M",[date of hire],Date())/12 AS [years since last evaluation] FROM tablename;

    Do some experimenting with the DateDiff and DateAdd functions. You will find that the DateDiff calc I show doesn't include partial current month. DateDiff rounds to the nearest whole unit.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    tdawn is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    3
    June7, thank you so much... I can't wait to get to work on Monday and try this out. I'll let you know how it goes Thank you again for your time!!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Review this link which has a good discussion on calculating dates https://www.accessforums.net/forms/d...ton-33572.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Access 2007 Query formula
    By malacqua in forum Sample Databases
    Replies: 9
    Last Post: 08-11-2012, 07:20 PM
  2. Average formula on access
    By chivo123 in forum Access
    Replies: 2
    Last Post: 01-28-2012, 11:31 AM
  3. Excel Formula Needed in Access
    By bmschaeffer in forum Queries
    Replies: 4
    Last Post: 01-18-2012, 01:13 PM
  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